home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / Thread Manager Extension 2.0.1 / Thread Manager Documentation < prev    next >
MacBinary  |  1994-06-03  |  137.8 KB  |  [ONLN/HLX2]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: MacBinary (archive/macBinary).

ConfidenceProgramDetectionMatch TypeSupport
10% dexvert MacBinary (archive/macBinary) fallback Supported
100% file MacBinary II, inited, Sun May 1 14:04:04 1994, modified Fri Jun 3 11:07:36 1994, creator 'HLX2', type 'ONLN', 137220 bytes "Thread Manager Documentation" , at 0x21884 3523 bytes resource default (weak)
99% file data default
66% TrID SpeedScript document (C64) default (weak)
33% TrID MacBinary 2 default (weak)
100% siegfried fmt/1762 MacBinary (II) default
100% lsar MacBinary default


id metadata
keyvalue
macFileType[ONLN]
macFileCreator[HLX2]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 1c 54 68 72 65 61 64 | 20 4d 61 6e 61 67 65 72 |..Thread| Manager|
|00000010| 20 44 6f 63 75 6d 65 6e | 74 61 74 69 6f 6e 00 00 | Documen|tation..|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 4f 4e 4c 4e 48 4c 58 | 32 01 00 00 00 00 00 00 |.ONLNHLX|2.......|
|00000050| 00 00 00 00 02 18 04 00 | 00 0d c3 a9 e9 9f 94 aa |........|........|
|00000060| 14 f7 b8 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 25 ce 00 00 |........|....%...|
|00000080| f0 a8 20 41 70 70 6c 65 | 20 43 6f 6d 70 75 74 65 |.. Apple| Compute|
|00000090| 72 2c 20 49 6e 63 2e 20 | 0d 54 68 72 65 61 64 20 |r, Inc. |.Thread |
|000000a0| 4d 61 6e 61 67 65 72 20 | 66 6f 72 20 4d 61 63 69 |Manager |for Maci|
|000000b0| 6e 74 6f 73 68 20 41 70 | 70 6c 69 63 61 74 69 6f |ntosh Ap|plicatio|
|000000c0| 6e 73 0d 46 69 6e 61 6c | 20 44 72 61 66 74 0d 52 |ns.Final| Draft.R|
|000000d0| 65 76 69 73 69 6f 6e 20 | 32 2e 30 0d 4a 61 6e 75 |evision |2.0.Janu|
|000000e0| 61 72 79 20 32 34 2c 20 | 31 39 39 34 0d 50 6c 65 |ary 24, |1994.Ple|
|000000f0| 61 73 65 20 66 6f 72 77 | 61 72 64 20 63 6f 6d 6d |ase forw|ard comm|
|00000100| 65 6e 74 73 20 74 6f 3a | 0d 41 4c 69 6e 6b 3a 20 |ents to:|.ALink: |
|00000110| 44 45 56 53 55 50 50 4f | 52 54 0d a9 31 39 39 34 |DEVSUPPO|RT..1994|
|00000120| 2c 20 41 70 70 6c 65 20 | 43 6f 6d 70 75 74 65 72 |, Apple |Computer|
|00000130| 2c 20 49 6e 63 2e 0d 41 | 6c 6c 20 72 69 67 68 74 |, Inc..A|ll right|
|00000140| 73 20 72 65 73 65 72 76 | 65 64 2e 0d 54 48 52 45 |s reserv|ed..THRE|
|00000150| 41 44 20 4d 41 4e 41 47 | 45 52 20 44 45 56 45 4c |AD MANAG|ER DEVEL|
|00000160| 4f 50 4d 45 4e 54 20 47 | 55 49 44 45 0d 45 58 45 |OPMENT G|UIDE.EXE|
|00000170| 43 55 54 49 56 45 20 53 | 55 4d 4d 41 52 59 0d 50 |CUTIVE S|UMMARY.P|
|00000180| 75 72 70 6f 73 65 20 6f | 66 20 74 68 69 73 20 64 |urpose o|f this d|
|00000190| 6f 63 75 6d 65 6e 74 0d | 09 54 68 69 73 20 70 61 |ocument.|.This pa|
|000001a0| 70 65 72 20 77 69 6c 6c | 20 70 72 6f 76 69 64 65 |per will| provide|
|000001b0| 20 74 68 65 20 72 65 61 | 64 65 72 20 77 69 74 68 | the rea|der with|
|000001c0| 20 74 68 65 20 6d 6f 74 | 69 76 61 74 69 6f 6e 2c | the mot|ivation,|
|000001d0| 20 61 72 63 68 69 74 65 | 63 74 75 72 65 2c 20 61 | archite|cture, a|
|000001e0| 6e 64 20 70 72 6f 67 72 | 61 6d 6d 61 74 69 63 20 |nd progr|ammatic |
|000001f0| 69 6e 74 65 72 66 61 63 | 65 20 6f 66 20 74 68 65 |interfac|e of the|
|00000200| 20 54 68 72 65 61 64 20 | 4d 61 6e 61 67 65 72 2e | Thread |Manager.|
|00000210| 20 54 68 65 20 61 72 63 | 68 69 74 65 63 74 75 72 | The arc|hitectur|
|00000220| 65 20 73 65 63 74 69 6f | 6e 20 77 69 6c 6c 20 67 |e sectio|n will g|
|00000230| 69 76 65 20 73 6f 6d 65 | 20 64 65 74 61 69 6c 20 |ive some| detail |
|00000240| 6f 66 20 68 6f 77 20 74 | 68 65 20 54 68 72 65 61 |of how t|he Threa|
|00000250| 64 20 4d 61 6e 61 67 65 | 72 20 69 73 20 69 6e 74 |d Manage|r is int|
|00000260| 65 67 72 61 74 65 64 20 | 69 6e 74 6f 20 74 68 65 |egrated |into the|
|00000270| 20 4d 61 63 69 6e 74 6f | 73 68 20 65 6e 76 69 72 | Macinto|sh envir|
|00000280| 6f 6e 6d 65 6e 74 20 61 | 6e 64 20 73 6f 6d 65 20 |onment a|nd some |
|00000290| 6f 66 20 74 68 65 20 61 | 73 73 75 6d 70 74 69 6f |of the a|ssumptio|
|000002a0| 6e 73 20 6d 61 64 65 20 | 69 6e 20 69 74 73 20 64 |ns made |in its d|
|000002b0| 65 73 69 67 6e 2e 20 54 | 68 65 20 70 72 6f 67 72 |esign. T|he progr|
|000002c0| 61 6d 6d 61 74 69 63 20 | 69 6e 74 65 72 66 61 63 |ammatic |interfac|
|000002d0| 65 20 77 69 6c 6c 20 74 | 68 65 6e 20 62 65 20 64 |e will t|hen be d|
|000002e0| 65 73 63 72 69 62 65 64 | 20 77 69 74 68 20 63 6f |escribed| with co|
|000002f0| 6d 6d 65 6e 74 61 72 79 | 20 6f 6e 20 74 68 65 20 |mmentary| on the |
|00000300| 75 73 65 20 6f 66 20 65 | 61 63 68 20 6f 66 20 74 |use of e|ach of t|
|00000310| 68 65 20 72 6f 75 74 69 | 6e 65 73 2e 20 54 68 65 |he routi|nes. The|
|00000320| 20 65 6e 64 20 70 61 70 | 65 72 20 63 6f 6e 74 61 | end pap|er conta|
|00000330| 69 6e 73 20 69 6e 66 6f | 72 6d 61 74 69 6f 6e 20 |ins info|rmation |
|00000340| 73 75 63 68 20 61 73 20 | 63 75 72 72 65 6e 74 20 |such as |current |
|00000350| 6b 6e 6f 77 6e 20 62 75 | 67 73 20 61 6e 64 20 63 |known bu|gs and c|
|00000360| 6f 6d 70 61 74 69 62 69 | 6c 69 74 79 20 69 73 73 |ompatibi|lity iss|
|00000370| 75 65 73 2e 0d 50 72 6f | 64 75 63 74 20 44 65 66 |ues..Pro|duct Def|
|00000380| 69 6e 69 74 69 6f 6e 0d | 09 54 68 65 20 54 68 72 |inition.|.The Thr|
|00000390| 65 61 64 20 4d 61 6e 61 | 67 65 72 20 69 73 20 74 |ead Mana|ger is t|
|000003a0| 68 65 20 63 75 72 72 65 | 6e 74 20 4d 61 63 4f 53 |he curre|nt MacOS|
|000003b0| 20 73 6f 6c 75 74 69 6f | 6e 20 66 6f 72 20 6c 69 | solutio|n for li|
|000003c0| 67 68 74 77 65 69 67 68 | 74 20 63 6f 6e 63 75 72 |ghtweigh|t concur|
|000003d0| 72 65 6e 74 20 70 72 6f | 63 65 73 73 69 6e 67 2e |rent pro|cessing.|
|000003e0| 20 4d 75 6c 74 69 74 68 | 72 65 61 64 69 6e 67 20 | Multith|reading |
|000003f0| 61 6c 6c 6f 77 73 20 61 | 6e 20 61 70 70 6c 69 63 |allows a|n applic|
|00000400| 61 74 69 6f 6e 20 70 72 | 6f 63 65 73 73 20 74 6f |ation pr|ocess to|
|00000410| 20 62 65 20 62 72 6f 6b | 65 6e 20 69 6e 74 6f 20 | be brok|en into |
|00000420| 73 69 6d 70 6c 65 20 73 | 75 62 70 72 6f 63 65 73 |simple s|ubproces|
|00000430| 73 65 73 20 74 68 61 74 | 20 70 72 6f 63 65 65 64 |ses that| proceed|
|00000440| 20 63 6f 6e 63 75 72 72 | 65 6e 74 6c 79 20 69 6e | concurr|ently in|
|00000450| 20 74 68 65 20 73 61 6d | 65 20 6f 76 65 72 61 6c | the sam|e overal|
|00000460| 6c 20 61 70 70 6c 69 63 | 61 74 69 6f 6e 20 63 6f |l applic|ation co|
|00000470| 6e 74 65 78 74 2e 20 43 | 6f 6e 63 65 70 74 75 61 |ntext. C|onceptua|
|00000480| 6c 6c 79 2c 20 61 20 74 | 68 72 65 61 64 20 69 73 |lly, a t|hread is|
|00000490| 20 74 68 65 20 73 6d 61 | 6c 6c 65 73 74 20 61 6d | the sma|llest am|
|000004a0| 6f 75 6e 74 20 6f 66 20 | 70 72 6f 63 65 73 73 6f |ount of |processo|
|000004b0| 72 20 63 6f 6e 74 65 78 | 74 20 73 74 61 74 65 20 |r contex|t state |
|000004c0| 6e 65 63 65 73 73 61 72 | 79 20 74 6f 20 65 6e 63 |necessar|y to enc|
|000004d0| 61 70 73 75 6c 61 74 65 | 20 61 20 63 6f 6d 70 75 |apsulate| a compu|
|000004e0| 74 61 74 69 6f 6e 2e 20 | 50 72 61 63 74 69 63 61 |tation. |Practica|
|000004f0| 6c 6c 79 20 73 70 65 61 | 6b 69 6e 67 2c 20 61 20 |lly spea|king, a |
|00000500| 74 68 72 65 61 64 20 63 | 6f 6e 73 69 73 74 73 20 |thread c|onsists |
|00000510| 6f 66 20 61 20 72 65 67 | 69 73 74 65 72 20 73 65 |of a reg|ister se|
|00000520| 74 2c 20 61 20 70 72 6f | 67 72 61 6d 20 63 6f 75 |t, a pro|gram cou|
|00000530| 6e 74 65 72 2c 20 61 6e | 64 20 61 20 73 74 61 63 |nter, an|d a stac|
|00000540| 6b 2e 20 54 68 72 65 61 | 64 73 20 68 61 76 65 20 |k. Threa|ds have |
|00000550| 61 20 66 61 73 74 20 63 | 6f 6e 74 65 78 74 20 73 |a fast c|ontext s|
|00000560| 77 69 74 63 68 20 74 69 | 6d 65 20 64 75 65 20 74 |witch ti|me due t|
|00000570| 6f 20 74 68 65 69 72 20 | 6d 69 6e 69 6d 61 6c 20 |o their |minimal |
|00000580| 63 6f 6e 74 65 78 74 20 | 73 74 61 74 65 20 72 65 |context |state re|
|00000590| 71 75 69 72 65 6d 65 6e | 74 20 61 6e 64 20 6f 70 |quiremen|t and op|
|000005a0| 65 72 61 74 65 20 77 69 | 74 68 69 6e 20 74 68 65 |erate wi|thin the|
|000005b0| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 20 63 6f 6e | applica|tion con|
|000005c0| 74 65 78 74 20 77 68 69 | 63 68 20 67 69 76 65 73 |text whi|ch gives|
|000005d0| 20 74 68 72 65 61 64 73 | 20 66 75 6c 6c 20 61 70 | threads| full ap|
|000005e0| 70 6c 69 63 61 74 69 6f | 6e 20 67 6c 6f 62 61 6c |plicatio|n global|
|000005f0| 20 61 63 63 65 73 73 2e | 20 53 69 6e 63 65 20 74 | access.| Since t|
|00000600| 68 72 65 61 64 73 20 61 | 72 65 20 68 6f 73 74 65 |hreads a|re hoste|
|00000610| 64 20 62 79 20 61 6e 20 | 61 70 70 6c 69 63 61 74 |d by an |applicat|
|00000620| 69 6f 6e 2c 20 74 68 72 | 65 61 64 73 20 77 69 74 |ion, thr|eads wit|
|00000630| 68 69 6e 20 61 20 67 69 | 76 65 6e 20 61 70 70 6c |hin a gi|ven appl|
|00000640| 69 63 61 74 69 6f 6e 20 | 73 68 61 72 65 20 74 68 |ication |share th|
|00000650| 65 20 61 64 64 72 65 73 | 73 20 73 70 61 63 65 2c |e addres|s space,|
|00000660| 20 66 69 6c 65 20 61 63 | 63 65 73 73 20 70 61 74 | file ac|cess pat|
|00000670| 68 73 20 61 6e 64 20 6f | 74 68 65 72 20 73 79 73 |hs and o|ther sys|
|00000680| 74 65 6d 20 72 65 73 6f | 75 72 63 65 73 20 61 73 |tem reso|urces as|
|00000690| 73 6f 63 69 61 74 65 64 | 20 77 69 74 68 20 74 68 |sociated| with th|
|000006a0| 61 74 20 61 70 70 6c 69 | 63 61 74 69 6f 6e 2e 20 |at appli|cation. |
|000006b0| 54 68 69 73 20 68 69 67 | 68 20 64 65 67 72 65 65 |This hig|h degree|
|000006c0| 20 6f 66 20 64 61 74 61 | 20 73 68 61 72 69 6e 67 | of data| sharing|
|000006d0| 20 65 6e 61 62 6c 65 73 | 20 74 68 72 65 61 64 73 | enables| threads|
|000006e0| 20 74 6f 20 62 65 20 22 | 6c 69 67 68 74 77 65 69 | to be "|lightwei|
|000006f0| 67 68 74 22 20 61 6e 64 | 20 74 68 65 20 63 6f 6e |ght" and| the con|
|00000700| 74 65 78 74 20 73 77 69 | 74 63 68 65 73 20 74 6f |text swi|tches to|
|00000710| 20 62 65 20 76 65 72 79 | 20 66 61 73 74 20 72 65 | be very| fast re|
|00000720| 6c 61 74 69 76 65 20 74 | 6f 20 74 68 65 20 68 65 |lative t|o the he|
|00000730| 61 76 79 77 65 69 67 68 | 74 20 63 6f 6e 74 65 78 |avyweigh|t contex|
|00000740| 74 20 73 77 69 74 63 68 | 65 73 20 62 65 74 77 65 |t switch|es betwe|
|00000750| 65 6e 20 50 72 6f 63 65 | 73 73 20 4d 61 6e 61 67 |en Proce|ss Manag|
|00000760| 65 72 20 70 72 6f 63 65 | 73 73 65 73 2e 0d 20 09 |er proce|sses.. .|
|00000770| 41 6e 20 65 78 65 63 75 | 74 69 6f 6e 20 63 6f 6e |An execu|tion con|
|00000780| 74 65 78 74 20 72 65 71 | 75 69 72 65 73 20 70 72 |text req|uires pr|
|00000790| 6f 63 65 73 73 6f 72 20 | 74 69 6d 65 20 74 6f 20 |ocessor |time to |
|000007a0| 67 65 74 20 61 6e 79 74 | 68 69 6e 67 20 64 6f 6e |get anyt|hing don|
|000007b0| 65 2c 20 61 6e 64 20 74 | 68 65 72 65 20 63 61 6e |e, and t|here can|
|000007c0| 20 62 65 20 6f 6e 6c 79 | 20 6f 6e 65 20 74 68 72 | be only| one thr|
|000007d0| 65 61 64 20 61 74 20 61 | 20 74 69 6d 65 20 75 73 |ead at a| time us|
|000007e0| 69 6e 67 20 74 68 65 20 | 70 72 6f 63 65 73 73 6f |ing the |processo|
|000007f0| 72 2e 20 20 53 6f 2c 20 | 6a 75 73 74 20 6c 69 6b |r. So, |just lik|
|00000800| 65 20 61 70 70 6c 69 63 | 61 74 69 6f 6e 73 2c 20 |e applic|ations, |
|00000810| 74 68 72 65 61 64 73 20 | 61 72 65 20 73 63 68 65 |threads |are sche|
|00000820| 64 75 6c 65 64 20 74 6f | 20 73 68 61 72 65 20 74 |duled to| share t|
|00000830| 68 65 20 43 50 55 2c 20 | 61 6e 64 20 74 68 65 20 |he CPU, |and the |
|00000840| 43 50 55 20 74 69 6d 65 | 20 69 73 20 73 63 68 65 |CPU time| is sche|
|00000850| 64 75 6c 65 64 20 69 6e | 20 6f 6e 65 20 6f 66 20 |duled in| one of |
|00000860| 74 77 6f 20 77 61 79 73 | 2e 20 74 68 65 20 54 68 |two ways|. the Th|
|00000870| 72 65 61 64 20 4d 61 6e | 61 67 65 72 20 77 69 6c |read Man|ager wil|
|00000880| 6c 20 70 72 6f 76 69 64 | 65 20 62 6f 74 68 20 63 |l provid|e both c|
|00000890| 6f 6f 70 65 72 61 74 69 | 76 65 20 61 6e 64 20 70 |ooperati|ve and p|
|000008a0| 72 65 65 6d 70 74 69 76 | 65 20 74 68 72 65 61 64 |reemptiv|e thread|
|000008b0| 73 2e 20 43 6f 6f 70 65 | 72 61 74 69 76 65 20 74 |s. Coope|rative t|
|000008c0| 68 72 65 61 64 73 20 65 | 78 70 6c 69 63 69 74 6c |hreads e|xplicitl|
|000008d0| 79 20 69 6e 64 69 63 61 | 74 65 20 77 68 65 6e 20 |y indica|te when |
|000008e0| 74 68 65 79 20 61 72 65 | 20 67 69 76 69 6e 67 20 |they are| giving |
|000008f0| 75 70 20 74 68 65 20 43 | 50 55 2e 20 50 72 65 65 |up the C|PU. Pree|
|00000900| 6d 70 74 69 76 65 20 74 | 68 72 65 61 64 73 20 63 |mptive t|hreads c|
|00000910| 61 6e 20 62 65 20 69 6e | 74 65 72 72 75 70 74 65 |an be in|terrupte|
|00000920| 64 20 61 6e 64 20 67 61 | 69 6e 20 63 6f 6e 74 72 |d and ga|in contr|
|00000930| 6f 6c 20 61 74 20 28 6d | 6f 73 74 29 20 61 6e 79 |ol at (m|ost) any|
|00000940| 20 74 69 6d 65 2e 20 20 | 54 68 65 20 62 61 73 69 | time. |The basi|
|00000950| 73 20 66 6f 72 20 74 68 | 65 20 64 69 66 66 65 72 |s for th|e differ|
|00000960| 65 6e 63 65 20 69 73 20 | 74 68 61 74 20 74 68 65 |ence is |that the|
|00000970| 72 65 20 61 72 65 20 6d | 61 6e 79 20 70 61 72 74 |re are m|any part|
|00000980| 73 20 6f 66 20 74 68 65 | 20 4d 61 63 4f 53 20 61 |s of the| MacOS a|
|00000990| 6e 64 20 54 6f 6f 6c 62 | 6f 78 20 74 68 61 74 20 |nd Toolb|ox that |
|000009a0| 63 61 6e 20 6e 6f 74 20 | 66 75 6e 63 74 69 6f 6e |can not |function|
|000009b0| 20 70 72 6f 70 65 72 6c | 79 20 77 68 65 6e 20 69 | properl|y when i|
|000009c0| 6e 74 65 72 72 75 70 74 | 65 64 20 61 6e 64 2f 6f |nterrupt|ed and/o|
|000009d0| 72 20 65 78 65 63 75 74 | 65 64 20 61 74 20 61 72 |r execut|ed at ar|
|000009e0| 62 69 74 72 61 72 79 20 | 74 69 6d 65 73 2e 20 44 |bitrary |times. D|
|000009f0| 75 65 20 74 6f 20 74 68 | 69 73 20 72 65 73 74 72 |ue to th|is restr|
|00000a00| 69 63 74 69 6f 6e 2c 20 | 74 68 72 65 61 64 73 20 |iction, |threads |
|00000a10| 75 73 69 6e 67 20 73 75 | 63 68 20 73 65 72 76 69 |using su|ch servi|
|00000a20| 63 65 73 20 6d 75 73 74 | 20 62 65 20 63 6f 6f 70 |ces must| be coop|
|00000a30| 65 72 61 74 69 76 65 2e | 20 54 68 72 65 61 64 73 |erative.| Threads|
|00000a40| 20 74 68 61 74 20 64 6f | 20 6e 6f 74 20 75 73 65 | that do| not use|
|00000a50| 20 74 68 65 20 54 6f 6f | 6c 62 6f 78 20 6f 72 20 | the Too|lbox or |
|00000a60| 4f 53 20 6d 61 79 20 62 | 65 20 70 72 65 65 6d 70 |OS may b|e preemp|
|00000a70| 74 69 76 65 2e 0d 09 43 | 6f 6f 70 65 72 61 74 69 |tive...C|ooperati|
|00000a80| 76 65 20 74 68 72 65 61 | 64 73 20 6f 70 65 72 61 |ve threa|ds opera|
|00000a90| 74 65 20 75 6e 64 65 72 | 20 61 20 73 63 68 65 64 |te under| a sched|
|00000aa0| 75 6c 69 6e 67 20 6d 6f | 64 65 6c 20 73 69 6d 69 |uling mo|del simi|
|00000ab0| 6c 61 72 20 74 6f 20 74 | 68 65 20 50 72 6f 63 65 |lar to t|he Proce|
|00000ac0| 73 73 20 4d 61 6e 61 67 | 65 72 2c 20 77 68 65 72 |ss Manag|er, wher|
|00000ad0| 65 69 6e 20 74 68 65 79 | 20 6d 75 73 74 20 6d 61 |ein they| must ma|
|00000ae0| 6b 65 20 65 78 70 6c 69 | 63 69 74 20 63 61 6c 6c |ke expli|cit call|
|00000af0| 73 20 66 6f 72 20 6f 74 | 68 65 72 20 63 6f 6f 70 |s for ot|her coop|
|00000b00| 65 72 61 74 69 76 65 20 | 74 68 72 65 61 64 73 20 |erative |threads |
|00000b10| 74 6f 20 67 65 74 20 63 | 6f 6e 74 72 6f 6c 2e 20 |to get c|ontrol. |
|00000b20| 20 41 73 20 61 20 72 65 | 73 75 6c 74 2c 20 74 68 | As a re|sult, th|
|00000b30| 65 79 20 61 72 65 20 6e | 6f 74 20 6c 69 6d 69 74 |ey are n|ot limit|
|00000b40| 65 64 20 69 6e 20 74 68 | 65 20 63 61 6c 6c 73 20 |ed in th|e calls |
|00000b50| 74 68 65 79 20 63 61 6e | 20 6d 61 6b 65 20 61 73 |they can| make as|
|00000b60| 20 6c 6f 6e 67 20 61 73 | 20 79 69 65 6c 64 69 6e | long as| yieldin|
|00000b70| 67 20 63 61 6c 6c 73 20 | 61 72 65 20 70 72 6f 70 |g calls |are prop|
|00000b80| 65 72 6c 79 20 70 6c 61 | 63 65 64 2e 20 50 72 65 |erly pla|ced. Pre|
|00000b90| 65 6d 70 74 69 76 65 20 | 74 68 72 65 61 64 73 20 |emptive |threads |
|00000ba0| 6f 70 65 72 61 74 65 20 | 75 6e 64 65 72 20 61 20 |operate |under a |
|00000bb0| 74 69 6d 65 20 73 6c 69 | 63 65 20 73 63 68 65 64 |time sli|ce sched|
|00000bc0| 75 6c 69 6e 67 20 6d 6f | 64 65 6c 3b 20 6e 6f 20 |uling mo|del; no |
|00000bd0| 73 70 65 63 69 61 6c 20 | 63 61 6c 6c 73 20 61 72 |special |calls ar|
|00000be0| 65 20 72 65 71 75 69 72 | 65 64 20 74 6f 20 73 75 |e requir|ed to su|
|00000bf0| 72 72 65 6e 64 65 72 20 | 74 68 65 20 43 50 55 20 |rrender |the CPU |
|00000c00| 66 6f 72 20 6f 74 68 65 | 72 20 70 72 65 65 6d 70 |for othe|r preemp|
|00000c10| 74 69 76 65 20 6f 72 20 | 63 6f 6f 70 65 72 61 74 |tive or |cooperat|
|00000c20| 69 76 65 20 74 68 72 65 | 61 64 73 20 74 6f 20 67 |ive thre|ads to g|
|00000c30| 61 69 6e 20 63 6f 6e 74 | 72 6f 6c 2e 20 46 6f 72 |ain cont|rol. For|
|00000c40| 20 74 68 72 65 61 64 73 | 20 77 68 69 63 68 20 61 | threads| which a|
|00000c50| 72 65 20 63 6f 6d 70 75 | 74 65 2d 62 6f 75 6e 64 |re compu|te-bound|
|00000c60| 20 6f 72 20 75 73 65 20 | 4d 61 63 4f 53 20 61 6e | or use |MacOS an|
|00000c70| 64 20 54 6f 6f 6c 62 6f | 78 20 63 61 6c 6c 73 20 |d Toolbo|x calls |
|00000c80| 74 68 61 74 20 63 61 6e | 20 62 65 20 69 6e 74 65 |that can| be inte|
|00000c90| 72 72 75 70 74 65 64 2c | 20 70 72 65 65 6d 70 74 |rrupted,| preempt|
|00000ca0| 69 76 65 20 74 68 72 65 | 61 64 73 20 6d 61 79 20 |ive thre|ads may |
|00000cb0| 62 65 20 74 68 65 20 62 | 65 73 74 20 63 68 6f 69 |be the b|est choi|
|00000cc0| 63 65 3b 20 74 68 65 20 | 72 65 73 75 6c 74 69 6e |ce; the |resultin|
|00000cd0| 67 20 63 6f 64 65 20 69 | 73 20 63 6c 65 61 6e 65 |g code i|s cleane|
|00000ce0| 72 20 74 68 61 6e 20 69 | 66 20 70 61 72 74 69 61 |r than i|f partia|
|00000cf0| 6c 20 72 65 73 75 6c 74 | 73 20 77 65 72 65 20 73 |l result|s were s|
|00000d00| 61 76 65 64 20 61 6e 64 | 20 63 6f 6e 74 72 6f 6c |aved and| control|
|00000d10| 20 74 68 65 6e 20 68 61 | 6e 64 65 64 20 6f 66 66 | then ha|nded off|
|00000d20| 20 74 6f 20 6f 74 68 65 | 72 20 74 68 72 65 61 64 | to othe|r thread|
|00000d30| 73 20 6f 66 20 63 6f 6e | 74 72 6f 6c 2e 0d 50 61 |s of con|trol..Pa|
|00000d40| 72 74 20 31 3a 20 52 45 | 51 55 49 52 45 4d 45 4e |rt 1: RE|QUIREMEN|
|00000d50| 54 53 20 53 55 4d 4d 41 | 52 59 0d 42 61 73 69 63 |TS SUMMA|RY.Basic|
|00000d60| 20 53 74 61 74 65 6d 65 | 6e 74 20 6f 66 20 4e 65 | Stateme|nt of Ne|
|00000d70| 65 64 0d 09 54 68 65 20 | 54 68 72 65 61 64 20 4d |ed..The |Thread M|
|00000d80| 61 6e 61 67 65 72 20 69 | 73 20 61 6e 20 6f 70 65 |anager i|s an ope|
|00000d90| 72 61 74 69 6e 67 20 73 | 79 73 74 65 6d 20 65 6e |rating s|ystem en|
|00000da0| 68 61 6e 63 65 6d 65 6e | 74 20 74 68 61 74 20 77 |hancemen|t that w|
|00000db0| 69 6c 6c 20 61 6c 6c 6f | 77 20 61 70 70 6c 69 63 |ill allo|w applic|
|00000dc0| 61 74 69 6f 6e 73 20 74 | 6f 20 6d 61 6b 65 20 75 |ations t|o make u|
|00000dd0| 73 65 20 6f 66 20 62 6f | 74 68 20 63 6f 6f 70 65 |se of bo|th coope|
|00000de0| 72 61 74 69 76 65 20 26 | 20 70 72 65 65 6d 70 74 |rative &| preempt|
|00000df0| 69 76 65 20 6d 75 6c 74 | 69 74 61 73 6b 69 6e 67 |ive mult|itasking|
|00000e00| 20 77 69 74 68 69 6e 20 | 74 68 65 69 72 20 61 70 | within |their ap|
|00000e10| 70 6c 69 63 61 74 69 6f | 6e 20 63 6f 6e 74 65 78 |plicatio|n contex|
|00000e20| 74 20 6f 6e 20 61 6c 6c | 20 36 38 30 78 30 20 62 |t on all| 680x0 b|
|00000e30| 61 73 65 64 20 4d 61 63 | 69 6e 74 6f 73 68 20 70 |ased Mac|intosh p|
|00000e40| 6c 61 74 66 6f 72 6d 73 | 2c 20 61 6e 64 20 63 6f |latforms|, and co|
|00000e50| 6f 70 65 72 61 74 69 76 | 65 20 6d 75 6c 74 69 74 |operativ|e multit|
|00000e60| 61 73 6b 69 6e 67 20 6f | 6e 20 50 6f 77 65 72 50 |asking o|n PowerP|
|00000e70| 43 20 62 61 73 65 64 20 | 4d 61 63 69 6e 74 6f 73 |C based |Macintos|
|00000e80| 68 65 73 2e 20 54 68 65 | 72 65 20 61 72 65 20 74 |hes. The|re are t|
|00000e90| 77 6f 20 62 61 73 69 63 | 20 74 79 70 65 73 20 6f |wo basic| types o|
|00000ea0| 66 20 74 68 72 65 61 64 | 73 20 28 65 78 65 63 75 |f thread|s (execu|
|00000eb0| 74 69 6f 6e 20 63 6f 6e | 74 65 78 74 73 29 20 61 |tion con|texts) a|
|00000ec0| 76 61 69 6c 61 62 6c 65 | 3a 20 63 6f 6f 70 65 72 |vailable|: cooper|
|00000ed0| 61 74 69 76 65 20 61 6e | 64 20 70 72 65 65 6d 70 |ative an|d preemp|
|00000ee0| 74 69 76 65 2e 20 54 68 | 65 20 64 69 66 66 65 72 |tive. Th|e differ|
|00000ef0| 65 6e 74 20 74 79 70 65 | 73 20 6f 66 20 74 68 72 |ent type|s of thr|
|00000f00| 65 61 64 73 20 61 72 65 | 20 64 69 73 74 69 6e 67 |eads are| disting|
|00000f10| 75 69 73 68 65 64 20 62 | 79 20 74 68 65 69 72 20 |uished b|y their |
|00000f20| 73 63 68 65 64 75 6c 69 | 6e 67 20 6d 6f 64 65 6c |scheduli|ng model|
|00000f30| 73 2e 0d 09 54 68 65 20 | 62 65 6e 65 66 69 74 73 |s...The |benefits|
|00000f40| 20 6f 66 20 70 65 72 2d | 61 70 70 6c 69 63 61 74 | of per-|applicat|
|00000f50| 69 6f 6e 20 6d 75 6c 74 | 69 74 61 73 6b 69 6e 67 |ion mult|itasking|
|00000f60| 20 61 72 65 20 6e 75 6d | 65 72 6f 75 73 2e 20 4d | are num|erous. M|
|00000f70| 61 6e 79 20 61 70 70 6c | 69 63 61 74 69 6f 6e 73 |any appl|ications|
|00000f80| 20 61 72 65 20 62 65 73 | 74 20 73 74 72 75 63 74 | are bes|t struct|
|00000f90| 75 72 65 64 20 61 73 20 | 73 65 76 65 72 61 6c 20 |ured as |several |
|00000fa0| 69 6e 64 65 70 65 6e 64 | 65 6e 74 20 65 78 65 63 |independ|ent exec|
|00000fb0| 75 74 69 6f 6e 20 63 6f | 6e 74 65 78 74 73 2e 20 |ution co|ntexts. |
|00000fc0| 41 6e 20 69 6d 61 67 65 | 20 70 72 6f 63 65 73 73 |An image| process|
|00000fd0| 69 6e 67 20 61 70 70 6c | 69 63 61 74 69 6f 6e 20 |ing appl|ication |
|00000fe0| 6d 69 67 68 74 20 77 61 | 6e 74 20 74 6f 20 72 75 |might wa|nt to ru|
|00000ff0| 6e 20 61 20 66 69 6c 74 | 65 72 20 6f 6e 20 61 20 |n a filt|er on a |
|00001000| 73 65 6c 65 63 74 65 64 | 20 61 72 65 61 20 61 6e |selected| area an|
|00001010| 64 20 73 74 69 6c 6c 20 | 61 6c 6c 6f 77 20 74 68 |d still |allow th|
|00001020| 65 20 75 73 65 72 20 74 | 6f 20 63 6f 6e 74 69 6e |e user t|o contin|
|00001030| 75 65 20 77 6f 72 6b 20 | 6f 6e 20 61 6e 6f 74 68 |ue work |on anoth|
|00001040| 65 72 20 70 6f 72 74 69 | 6f 6e 20 6f 66 20 61 6e |er porti|on of an|
|00001050| 20 69 6d 61 67 65 2e 20 | 41 20 64 61 74 61 62 61 | image. |A databa|
|00001060| 73 65 20 61 70 70 6c 69 | 63 61 74 69 6f 6e 20 6d |se appli|cation m|
|00001070| 61 79 20 61 6c 6c 6f 77 | 20 61 20 75 73 65 72 20 |ay allow| a user |
|00001080| 74 6f 20 64 6f 20 61 20 | 73 65 61 72 63 68 20 77 |to do a |search w|
|00001090| 68 69 6c 65 20 63 6f 6e | 63 75 72 72 65 6e 74 6c |hile con|currentl|
|000010a0| 79 20 61 64 64 69 6e 67 | 20 65 6e 74 72 69 65 73 |y adding| entries|
|000010b0| 20 6f 76 65 72 20 61 20 | 6e 65 74 77 6f 72 6b 2e | over a |network.|
|000010c0| 20 57 69 74 68 20 74 68 | 65 20 54 68 72 65 61 64 | With th|e Thread|
|000010d0| 20 4d 61 6e 61 67 65 72 | 2c 20 69 74 20 69 73 20 | Manager|, it is |
|000010e0| 6e 6f 77 20 70 6f 73 73 | 69 62 6c 65 20 74 6f 20 |now poss|ible to |
|000010f0| 61 6c 77 61 79 73 20 6d | 61 6b 65 20 61 70 70 6c |always m|ake appl|
|00001100| 69 63 61 74 69 6f 6e 73 | 20 72 65 73 70 6f 6e 73 |ications| respons|
|00001110| 69 76 65 20 74 6f 20 74 | 68 65 20 75 73 65 72 2c |ive to t|he user,|
|00001120| 20 65 76 65 6e 20 77 68 | 69 6c 65 20 65 78 65 63 | even wh|ile exec|
|00001130| 75 74 69 6e 67 20 6f 74 | 68 65 72 20 6f 70 65 72 |uting ot|her oper|
|00001140| 61 74 69 6f 6e 73 2e 20 | 54 68 65 20 54 68 72 65 |ations. |The Thre|
|00001150| 61 64 20 4d 61 6e 61 67 | 65 72 20 61 6c 73 6f 20 |ad Manag|er also |
|00001160| 67 69 76 65 73 20 61 70 | 70 6c 69 63 61 74 69 6f |gives ap|plicatio|
|00001170| 6e 73 20 61 6e 20 65 61 | 73 79 20 77 61 79 20 74 |ns an ea|sy way t|
|00001180| 6f 20 6f 72 67 61 6e 69 | 7a 65 20 6d 75 6c 74 69 |o organi|ze multi|
|00001190| 70 6c 65 20 69 6e 73 74 | 61 6e 63 65 73 20 6f 66 |ple inst|ances of|
|000011a0| 20 73 61 6d 65 20 6f 72 | 20 73 69 6d 69 6c 61 72 | same or| similar|
|000011b0| 20 63 6f 64 65 2e 20 49 | 6e 20 65 61 63 68 20 65 | code. I|n each e|
|000011c0| 78 61 6d 70 6c 65 20 69 | 74 20 69 73 20 70 6f 73 |xample i|t is pos|
|000011d0| 73 69 62 6c 65 20 74 6f | 20 77 72 69 74 65 20 74 |sible to| write t|
|000011e0| 68 65 20 73 6f 66 74 77 | 61 72 65 20 61 73 20 6f |he softw|are as o|
|000011f0| 6e 65 20 74 68 72 65 61 | 64 20 6f 66 20 65 78 65 |ne threa|d of exe|
|00001200| 63 75 74 69 6f 6e 2c 20 | 68 6f 77 65 76 65 72 2c |cution, |however,|
|00001210| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 20 63 6f 64 | applica|tion cod|
|00001220| 65 20 6d 61 79 20 62 65 | 20 73 69 6d 70 6c 69 66 |e may be| simplif|
|00001230| 69 65 64 20 62 79 20 77 | 72 69 74 69 6e 67 20 65 |ied by w|riting e|
|00001240| 61 63 68 20 63 6c 61 73 | 73 20 6f 66 20 6f 70 65 |ach clas|s of ope|
|00001250| 72 61 74 69 6f 6e 20 61 | 73 20 61 20 73 65 70 61 |ration a|s a sepa|
|00001260| 72 61 74 65 20 74 68 72 | 65 61 64 20 61 6e 64 20 |rate thr|ead and |
|00001270| 6c 65 74 74 69 6e 67 20 | 74 68 65 20 54 68 72 65 |letting |the Thre|
|00001280| 61 64 20 4d 61 6e 61 67 | 65 72 20 68 61 6e 64 6c |ad Manag|er handl|
|00001290| 65 20 74 68 65 20 69 6e | 74 65 72 6c 65 61 76 69 |e the in|terleavi|
|000012a0| 6e 67 20 6f 66 20 74 68 | 65 20 74 68 72 65 61 64 |ng of th|e thread|
|000012b0| 65 64 20 65 78 65 63 75 | 74 69 6f 6e 20 63 6f 6e |ed execu|tion con|
|000012c0| 74 65 78 74 73 2e 0d 09 | 54 68 65 73 65 20 65 78 |texts...|These ex|
|000012d0| 61 6d 70 6c 65 73 20 61 | 72 65 20 6e 6f 74 20 69 |amples a|re not i|
|000012e0| 6e 74 65 6e 64 65 64 20 | 74 6f 20 62 65 20 65 78 |ntended |to be ex|
|000012f0| 68 61 75 73 74 69 76 65 | 2c 20 62 75 74 20 74 68 |haustive|, but th|
|00001300| 65 79 20 69 6e 64 69 63 | 61 74 65 20 74 68 65 20 |ey indic|ate the |
|00001310| 6f 70 70 6f 72 74 75 6e | 69 74 69 65 73 20 74 6f |opportun|ities to|
|00001320| 20 65 78 70 6c 6f 69 74 | 20 74 68 65 20 4d 61 63 | exploit| the Mac|
|00001330| 69 6e 74 6f 73 68 20 73 | 79 73 74 65 6d 20 61 6e |intosh s|ystem an|
|00001340| 64 20 62 75 69 6c 64 20 | 63 6f 6d 70 6c 65 78 20 |d build |complex |
|00001350| 61 70 70 6c 69 63 61 74 | 69 6f 6e 73 20 77 69 74 |applicat|ions wit|
|00001360| 68 20 74 68 69 73 20 74 | 65 63 68 6e 6f 6c 6f 67 |h this t|echnolog|
|00001370| 79 2e 20 54 68 65 20 65 | 78 61 6d 70 6c 65 73 20 |y. The e|xamples |
|00001380| 73 68 6f 77 20 74 68 61 | 74 20 74 68 65 20 6d 6f |show tha|t the mo|
|00001390| 64 65 6c 20 66 6f 72 20 | 6d 75 6c 74 69 70 6c 65 |del for |multiple|
|000013a0| 20 74 68 72 65 61 64 73 | 20 6f 66 20 63 6f 6e 74 | threads| of cont|
|000013b0| 72 6f 6c 20 6d 75 73 74 | 20 73 75 70 70 6f 72 74 |rol must| support|
|000013c0| 20 61 20 76 61 72 69 65 | 74 79 20 6f 66 20 61 70 | a varie|ty of ap|
|000013d0| 70 6c 69 63 61 74 69 6f | 6e 73 20 61 6e 64 20 75 |plicatio|ns and u|
|000013e0| 73 65 72 20 65 6e 76 69 | 72 6f 6e 6d 65 6e 74 73 |ser envi|ronments|
|000013f0| 2e 20 54 68 65 20 54 68 | 72 65 61 64 20 4d 61 6e |. The Th|read Man|
|00001400| 61 67 65 72 20 61 72 63 | 68 69 74 65 63 74 75 72 |ager arc|hitectur|
|00001410| 65 20 77 69 6c 6c 2c 20 | 77 68 65 72 65 20 70 6f |e will, |where po|
|00001420| 73 73 69 62 6c 65 2c 20 | 75 73 65 20 74 68 65 20 |ssible, |use the |
|00001430| 63 75 72 72 65 6e 74 20 | 4d 61 63 69 6e 74 6f 73 |current |Macintos|
|00001440| 68 20 70 72 6f 67 72 61 | 6d 6d 69 6e 67 20 70 61 |h progra|mming pa|
|00001450| 72 61 64 69 67 6d 73 20 | 61 6e 64 20 70 72 65 73 |radigms |and pres|
|00001460| 65 72 76 65 20 73 6f 66 | 74 77 61 72 65 20 63 6f |erve sof|tware co|
|00001470| 6d 70 61 74 69 62 69 6c | 69 74 79 2e 20 54 68 65 |mpatibil|ity. The|
|00001480| 20 54 68 72 65 61 64 20 | 4d 61 6e 61 67 65 72 20 | Thread |Manager |
|00001490| 65 6e 68 61 6e 63 65 73 | 20 74 68 65 20 70 72 6f |enhances| the pro|
|000014a0| 67 72 61 6d 6d 69 6e 67 | 20 6d 6f 64 65 6c 20 6f |gramming| model o|
|000014b0| 66 20 74 68 65 20 4d 61 | 63 69 6e 74 6f 73 68 20 |f the Ma|cintosh |
|000014c0| 66 6f 72 20 74 68 65 72 | 65 20 69 73 20 6c 69 74 |for ther|e is lit|
|000014d0| 74 6c 65 20 6e 65 65 64 | 20 74 6f 20 64 65 76 65 |tle need| to deve|
|000014e0| 6c 6f 70 20 54 69 6d 65 | 20 4d 61 6e 61 67 65 72 |lop Time| Manager|
|000014f0| 20 6f 72 20 56 42 4c 20 | 72 6f 75 74 69 6e 65 73 | or VBL |routines|
|00001500| 20 74 6f 20 70 72 6f 76 | 69 64 65 20 74 68 65 20 | to prov|ide the |
|00001510| 61 70 70 6c 69 63 61 74 | 69 6f 6e 20 77 69 74 68 |applicat|ion with|
|00001520| 20 61 20 70 72 65 65 6d | 70 74 69 76 65 20 65 78 | a preem|ptive ex|
|00001530| 65 63 75 74 69 6f 6e 20 | 63 6f 6e 74 65 78 74 2e |ecution |context.|
|00001540| 20 54 68 65 72 65 20 69 | 73 20 61 6c 73 6f 20 6e | There i|s also n|
|00001550| 6f 20 6e 65 65 64 20 74 | 6f 20 73 61 76 65 20 74 |o need t|o save t|
|00001560| 68 65 20 63 6f 6d 70 6c | 65 74 65 20 73 74 61 74 |he compl|ete stat|
|00001570| 65 20 6f 66 20 61 20 63 | 6f 6d 70 6c 65 78 20 63 |e of a c|omplex c|
|00001580| 61 6c 63 75 6c 61 74 69 | 6f 6e 20 69 6e 20 6f 72 |alculati|on in or|
|00001590| 64 65 72 20 74 6f 20 6d | 61 6b 65 20 57 61 69 74 |der to m|ake Wait|
|000015a0| 4e 65 78 74 45 76 65 6e | 74 20 6f 72 20 47 65 74 |NextEven|t or Get|
|000015b0| 4e 65 78 74 45 76 65 6e | 74 20 63 61 6c 6c 73 20 |NextEven|t calls |
|000015c0| 74 6f 20 62 65 20 75 73 | 65 72 20 72 65 73 70 6f |to be us|er respo|
|000015d0| 6e 73 69 76 65 20 2d 20 | 73 69 6d 70 6c 79 20 79 |nsive - |simply y|
|000015e0| 69 65 6c 64 20 74 6f 20 | 67 69 76 65 20 74 68 65 |ield to |give the|
|000015f0| 20 6d 61 69 6e 20 61 70 | 70 6c 63 69 61 74 69 6f | main ap|plciatio|
|00001600| 6e 20 74 68 72 65 61 64 | 20 61 20 63 68 61 6e 63 |n thread| a chanc|
|00001610| 65 20 74 6f 20 68 61 6e | 64 6c 65 20 69 6e 74 65 |e to han|dle inte|
|00001620| 72 66 61 63 65 20 6e 65 | 65 64 73 2e 0d 48 61 72 |rface ne|eds..Har|
|00001630| 64 77 61 72 65 20 43 6f | 6d 70 61 74 69 62 69 6c |dware Co|mpatibil|
|00001640| 69 74 79 0d 09 54 68 65 | 20 36 38 30 78 30 20 76 |ity..The| 680x0 v|
|00001650| 65 72 73 69 6f 6e 20 6f | 66 20 74 68 65 20 54 68 |ersion o|f the Th|
|00001660| 72 65 61 64 20 4d 61 6e | 61 67 65 72 20 68 61 73 |read Man|ager has|
|00001670| 20 74 68 65 20 73 61 6d | 65 20 68 61 72 64 77 61 | the sam|e hardwa|
|00001680| 72 65 20 72 65 71 75 69 | 72 65 6d 65 6e 74 73 20 |re requi|rements |
|00001690| 61 73 20 53 79 73 74 65 | 6d 20 37 2e 30 2c 20 74 |as Syste|m 7.0, t|
|000016a0| 68 61 74 20 69 73 2c 20 | 61 74 20 6c 65 61 73 74 |hat is, |at least|
|000016b0| 20 32 20 6d 65 67 61 62 | 79 74 65 73 20 6f 66 20 | 2 megab|ytes of |
|000016c0| 6d 65 6d 6f 72 79 2c 20 | 61 6e 64 20 61 20 4d 61 |memory, |and a Ma|
|000016d0| 63 69 6e 74 6f 73 68 20 | 50 6c 75 73 20 6f 72 20 |cintosh |Plus or |
|000016e0| 6e 65 77 65 72 20 43 50 | 55 2e 20 20 54 68 65 20 |newer CP|U. The |
|000016f0| 70 6f 77 65 72 20 76 65 | 72 73 69 6f 6e 20 6f 66 |power ve|rsion of|
|00001700| 20 74 68 65 20 54 68 72 | 65 61 64 20 4d 61 6e 61 | the Thr|ead Mana|
|00001710| 67 65 72 20 72 65 71 75 | 69 72 65 73 20 61 6e 79 |ger requ|ires any|
|00001720| 20 50 6f 77 65 72 20 4d | 61 63 69 6e 74 6f 73 68 | Power M|acintosh|
|00001730| 2e 0d 53 6f 66 74 77 61 | 72 65 20 43 6f 6d 70 61 |..Softwa|re Compa|
|00001740| 74 69 62 69 6c 69 74 79 | 0d 09 53 79 73 74 65 6d |tibility|..System|
|00001750| 20 37 2e 30 20 6f 72 20 | 67 72 65 61 74 65 72 20 | 7.0 or |greater |
|00001760| 69 73 20 72 65 71 75 69 | 72 65 64 20 66 6f 72 20 |is requi|red for |
|00001770| 74 68 65 20 36 38 30 78 | 30 20 76 65 72 73 69 6f |the 680x|0 versio|
|00001780| 6e 20 6f 66 20 74 68 65 | 20 54 68 72 65 61 64 20 |n of the| Thread |
|00001790| 4d 61 6e 61 67 65 72 20 | 74 6f 20 6f 70 65 72 61 |Manager |to opera|
|000017a0| 74 65 2e 20 20 54 68 65 | 20 70 6f 77 65 72 20 76 |te. The| power v|
|000017b0| 65 72 73 69 6f 6e 20 6f | 66 20 74 68 65 20 54 68 |ersion o|f the Th|
|000017c0| 72 65 61 64 20 4d 61 6e | 61 67 65 72 20 72 65 71 |read Man|ager req|
|000017d0| 75 69 72 65 73 20 73 79 | 73 74 65 6d 20 73 6f 66 |uires sy|stem sof|
|000017e0| 74 77 61 72 65 20 66 6f | 72 20 50 6f 77 65 72 20 |tware fo|r Power |
|000017f0| 4d 61 63 69 6e 74 6f 73 | 68 20 70 6c 61 74 66 6f |Macintos|h platfo|
|00001800| 72 6d 73 2e 0d 09 45 78 | 69 73 74 69 6e 67 20 61 |rms...Ex|isting a|
|00001810| 70 70 6c 69 63 61 74 69 | 6f 6e 73 20 74 68 61 74 |pplicati|ons that|
|00001820| 20 6b 6e 6f 77 20 6e 6f | 74 68 69 6e 67 20 61 62 | know no|thing ab|
|00001830| 6f 75 74 20 74 68 65 20 | 54 68 72 65 61 64 20 4d |out the |Thread M|
|00001840| 61 6e 61 67 65 72 20 68 | 61 76 65 20 6e 6f 74 68 |anager h|ave noth|
|00001850| 69 6e 67 20 74 6f 20 66 | 65 61 72 2e 20 20 54 68 |ing to f|ear. Th|
|00001860| 65 20 65 78 74 65 6e 74 | 20 6f 66 20 74 68 65 20 |e extent| of the |
|00001870| 54 68 72 65 61 64 20 4d | 61 6e 61 67 65 72 27 73 |Thread M|anager's|
|00001880| 20 69 6e 66 6c 75 65 6e | 63 65 20 69 73 20 74 6f | influen|ce is to|
|00001890| 20 73 65 74 20 75 70 20 | 74 68 65 20 6d 61 69 6e | set up |the main|
|000018a0| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 20 74 68 72 | applica|tion thr|
|000018b0| 65 61 64 20 77 68 65 6e | 20 74 68 65 20 61 70 70 |ead when| the app|
|000018c0| 6c 69 63 61 74 69 6f 6e | 20 69 73 20 6c 61 75 6e |lication| is laun|
|000018d0| 63 68 65 64 2c 20 20 61 | 6e 64 20 74 6f 20 6d 61 |ched, a|nd to ma|
|000018e0| 6b 65 20 61 6e 20 61 70 | 70 65 61 72 61 6e 63 65 |ke an ap|pearance|
|000018f0| 20 65 76 65 72 79 20 73 | 6f 20 6f 66 74 65 6e 20 | every s|o often |
|00001900| 61 73 20 74 68 65 20 70 | 72 65 65 6d 70 74 69 6f |as the p|reemptio|
|00001910| 6e 20 74 69 6d 65 72 20 | 66 69 72 65 73 20 6f 66 |n timer |fires of|
|00001920| 66 2e 20 20 42 65 63 61 | 75 73 65 20 74 68 65 72 |f. Beca|use ther|
|00001930| 65 20 69 73 20 6f 6e 6c | 79 20 74 68 65 20 61 70 |e is onl|y the ap|
|00001940| 70 6c 69 63 61 74 69 6f | 6e 20 74 68 72 65 61 64 |plicatio|n thread|
|00001950| 2c 20 74 68 65 20 70 72 | 65 65 6d 70 74 69 6f 6e |, the pr|eemption|
|00001960| 20 74 69 6d 65 72 20 68 | 61 73 20 6e 6f 74 68 69 | timer h|as nothi|
|00001970| 6e 67 20 74 6f 20 64 6f | 20 61 6e 64 20 71 75 69 |ng to do| and qui|
|00001980| 65 74 6c 79 20 72 65 74 | 75 72 6e 73 2e 20 20 54 |etly ret|urns. T|
|00001990| 68 75 73 2c 20 74 68 65 | 20 54 68 72 65 61 64 20 |hus, the| Thread |
|000019a0| 4d 61 6e 61 67 65 72 20 | 69 73 20 6e 65 61 72 6c |Manager |is nearl|
|000019b0| 79 20 74 72 61 6e 73 70 | 61 72 65 6e 74 20 74 6f |y transp|arent to|
|000019c0| 20 65 78 69 73 74 69 6e | 67 20 61 70 70 6c 69 63 | existin|g applic|
|000019d0| 61 74 69 6f 6e 73 2c 20 | 61 6e 64 20 6e 6f 20 63 |ations, |and no c|
|000019e0| 6f 6d 70 61 74 69 62 69 | 6c 69 74 79 20 63 6f 6e |ompatibi|lity con|
|000019f0| 63 65 72 6e 73 20 61 72 | 65 20 65 78 70 65 63 74 |cerns ar|e expect|
|00001a00| 65 64 2e 20 4e 65 77 20 | 61 70 70 6c 69 63 61 74 |ed. New |applicat|
|00001a10| 69 6f 6e 73 2c 20 6f 66 | 20 63 6f 75 72 73 65 2c |ions, of| course,|
|00001a20| 20 63 61 6e 20 72 65 61 | 70 20 74 68 65 20 66 75 | can rea|p the fu|
|00001a30| 6c 6c 20 62 65 6e 65 66 | 69 74 73 20 6f 66 20 63 |ll benef|its of c|
|00001a40| 6f 6e 63 75 72 72 65 6e | 74 20 70 72 6f 67 72 61 |oncurren|t progra|
|00001a50| 6d 6d 69 6e 67 2c 20 69 | 6e 63 6c 75 64 69 6e 67 |mming, i|ncluding|
|00001a60| 20 61 20 66 61 69 72 6c | 79 20 70 6f 77 65 72 66 | a fairl|y powerf|
|00001a70| 75 6c 20 66 6f 72 6d 20 | 6f 66 20 6d 75 6c 74 69 |ul form |of multi|
|00001a80| 74 61 73 6b 69 6e 67 2e | 0d 09 54 68 65 20 70 6f |tasking.|..The po|
|00001a90| 77 65 72 20 76 65 72 73 | 69 6f 6e 20 6f 66 20 74 |wer vers|ion of t|
|00001aa0| 68 65 20 54 68 72 65 61 | 64 20 4d 61 6e 61 67 65 |he Threa|d Manage|
|00001ab0| 72 20 69 73 20 62 75 69 | 6c 74 20 61 73 20 61 20 |r is bui|lt as a |
|00001ac0| 53 68 61 72 65 64 20 4c | 69 62 72 61 72 79 2c 20 |Shared L|ibrary, |
|00001ad0| 6e 61 6d 65 64 20 54 68 | 72 65 61 64 73 4c 69 62 |named Th|readsLib|
|00001ae0| 2c 20 74 68 61 74 20 69 | 73 20 66 75 6c 6c 79 20 |, that i|s fully |
|00001af0| 69 6e 74 65 67 72 61 74 | 65 64 20 69 6e 74 6f 20 |integrat|ed into |
|00001b00| 74 68 65 20 54 68 72 65 | 61 64 20 4d 61 6e 61 67 |the Thre|ad Manag|
|00001b10| 65 72 2e 0d 49 6e 74 65 | 6e 64 65 64 20 55 73 65 |er..Inte|nded Use|
|00001b20| 72 73 0d 09 44 65 76 65 | 6c 6f 70 65 72 73 20 77 |rs..Deve|lopers w|
|00001b30| 69 6c 6c 20 67 61 69 6e | 20 74 68 65 20 61 62 69 |ill gain| the abi|
|00001b40| 6c 69 74 79 20 74 6f 20 | 68 61 76 65 20 6d 75 6c |lity to |have mul|
|00001b50| 74 69 70 6c 65 2c 20 63 | 6f 6e 63 75 72 72 65 6e |tiple, c|oncurren|
|00001b60| 74 2c 20 6c 6f 67 69 63 | 61 6c 6c 79 20 73 65 70 |t, logic|ally sep|
|00001b70| 61 72 61 74 65 20 74 68 | 72 65 61 64 73 20 6f 66 |arate th|reads of|
|00001b80| 20 65 78 65 63 75 74 69 | 6f 6e 20 77 69 74 68 69 | executi|on withi|
|00001b90| 6e 20 74 68 65 69 72 20 | 61 70 70 6c 69 63 61 74 |n their |applicat|
|00001ba0| 69 6f 6e 2e 20 54 68 65 | 20 54 68 72 65 61 64 20 |ion. The| Thread |
|00001bb0| 4d 61 6e 61 67 65 72 20 | 77 69 6c 6c 20 70 72 6f |Manager |will pro|
|00001bc0| 76 69 64 65 20 4d 61 63 | 69 6e 74 6f 73 68 20 64 |vide Mac|intosh d|
|00001bd0| 65 76 65 6c 6f 70 65 72 | 73 20 77 69 74 68 20 61 |eveloper|s with a|
|00001be0| 20 73 74 61 74 65 20 6f | 66 20 74 68 65 20 61 72 | state o|f the ar|
|00001bf0| 74 20 66 6f 75 6e 64 61 | 74 69 6f 6e 20 66 6f 72 |t founda|tion for|
|00001c00| 20 62 75 69 6c 64 69 6e | 67 20 74 68 65 20 6e 65 | buildin|g the ne|
|00001c10| 78 74 20 67 65 6e 65 72 | 61 74 69 6f 6e 20 6f 66 |xt gener|ation of|
|00001c20| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 73 20 75 73 | applica|tions us|
|00001c30| 69 6e 67 20 61 20 6d 75 | 6c 74 69 2d 74 68 72 65 |ing a mu|lti-thre|
|00001c40| 61 64 65 64 20 61 70 70 | 6c 69 63 61 74 69 6f 6e |aded app|lication|
|00001c50| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 20 65 6e 76 | program|ming env|
|00001c60| 69 72 6f 6e 6d 65 6e 74 | 2e 20 41 6e 6f 74 68 65 |ironment|. Anothe|
|00001c70| 72 2c 20 6c 65 73 73 20 | 6f 62 76 69 6f 75 73 20 |r, less |obvious |
|00001c80| 75 73 65 72 20 69 73 20 | 73 79 73 74 65 6d 20 73 |user is |system s|
|00001c90| 6f 66 74 77 61 72 65 20 | 77 68 69 63 68 20 6f 70 |oftware |which op|
|00001ca0| 65 72 61 74 65 73 20 69 | 6e 20 74 68 65 20 61 70 |erates i|n the ap|
|00001cb0| 70 6c 69 63 61 74 69 6f | 6e 20 63 6f 6e 74 65 78 |plicatio|n contex|
|00001cc0| 74 2e 20 54 68 65 20 72 | 75 6c 65 20 6f 66 20 74 |t. The r|ule of t|
|00001cd0| 68 75 6d 62 20 69 73 3a | 20 43 6f 64 65 20 77 68 |humb is:| Code wh|
|00001ce0| 69 63 68 20 6f 70 65 72 | 61 74 65 73 20 6f 6e 6c |ich oper|ates onl|
|00001cf0| 79 20 77 69 74 68 69 6e | 20 61 6e 20 61 70 70 6c |y within| an appl|
|00001d00| 69 63 61 74 69 6f 6e 20 | 63 6f 6e 74 65 78 74 20 |ication |context |
|00001d10| 63 61 6e 20 75 73 65 20 | 74 68 65 20 54 68 72 65 |can use |the Thre|
|00001d20| 61 64 20 4d 61 6e 61 67 | 65 72 2c 20 63 6f 64 65 |ad Manag|er, code|
|00001d30| 20 74 68 61 74 20 64 6f | 65 73 20 6e 6f 74 2c 20 | that do|es not, |
|00001d40| 63 61 6e 20 6e 6f 74 2e | 0d 50 72 6f 67 72 61 6d |can not.|.Program|
|00001d50| 6d 61 74 69 63 20 49 6e | 74 65 72 66 61 63 65 20 |matic In|terface |
|00001d60| 44 65 73 63 72 69 70 74 | 69 6f 6e 0d 09 54 68 65 |Descript|ion..The|
|00001d70| 20 54 68 72 65 61 64 20 | 4d 61 6e 61 67 65 72 20 | Thread |Manager |
|00001d80| 70 65 72 66 6f 72 6d 73 | 20 63 72 65 61 74 69 6f |performs| creatio|
|00001d90| 6e 2c 20 73 63 68 65 64 | 75 6c 69 6e 67 20 61 6e |n, sched|uling an|
|00001da0| 64 20 64 65 6c 65 74 69 | 6f 6e 20 6f 66 20 74 68 |d deleti|on of th|
|00001db0| 72 65 61 64 73 2e 20 49 | 74 20 61 6c 6c 6f 77 73 |reads. I|t allows|
|00001dc0| 20 6d 75 6c 74 69 70 6c | 65 20 69 6e 64 65 70 65 | multipl|e indepe|
|00001dd0| 6e 64 65 6e 74 20 74 68 | 72 65 61 64 73 20 6f 66 |ndent th|reads of|
|00001de0| 20 65 78 65 63 75 74 69 | 6f 6e 20 77 69 74 68 69 | executi|on withi|
|00001df0| 6e 20 61 6e 20 61 70 70 | 6c 69 63 61 74 69 6f 6e |n an app|lication|
|00001e00| 2c 20 65 61 63 68 20 68 | 61 76 69 6e 67 20 69 74 |, each h|aving it|
|00001e10| 73 20 6f 77 6e 20 73 74 | 61 63 6b 20 61 6e 64 20 |s own st|ack and |
|00001e20| 73 74 61 74 65 2e 20 54 | 68 65 20 63 6c 69 65 6e |state. T|he clien|
|00001e30| 74 20 61 70 70 6c 69 63 | 61 74 69 6f 6e 20 63 61 |t applic|ation ca|
|00001e40| 6e 20 63 68 61 6e 67 65 | 20 74 68 65 20 73 63 68 |n change| the sch|
|00001e50| 65 64 75 6c 65 72 20 6f | 72 20 63 6f 6e 74 65 78 |eduler o|r contex|
|00001e60| 74 20 73 77 69 74 63 68 | 20 70 61 72 61 6d 65 74 |t switch| paramet|
|00001e70| 65 72 73 20 74 6f 20 6f | 70 74 69 6d 69 7a 65 20 |ers to o|ptimize |
|00001e80| 61 6e 20 61 70 70 6c 69 | 63 61 74 69 6f 6e 20 66 |an appli|cation f|
|00001e90| 6f 72 20 61 20 70 61 72 | 74 69 63 75 6c 61 72 20 |or a par|ticular |
|00001ea0| 75 73 61 67 65 20 70 61 | 74 74 65 72 6e 2e 0d 09 |usage pa|ttern...|
|00001eb0| 41 70 70 6c 69 63 61 74 | 69 6f 6e 73 20 77 69 6c |Applicat|ions wil|
|00001ec0| 6c 20 69 6e 74 65 72 66 | 61 63 65 20 77 69 74 68 |l interf|ace with|
|00001ed0| 20 74 68 65 20 54 68 72 | 65 61 64 20 4d 61 6e 61 | the Thr|ead Mana|
|00001ee0| 67 65 72 20 74 68 72 6f | 75 67 68 20 74 68 65 20 |ger thro|ugh the |
|00001ef0| 75 73 65 20 6f 66 20 74 | 68 65 20 54 72 61 70 20 |use of t|he Trap |
|00001f00| 6d 65 63 68 61 6e 69 73 | 6d 20 77 65 20 6b 6e 6f |mechanis|m we kno|
|00001f10| 77 20 61 6e 64 20 6c 6f | 76 65 2e 20 54 68 65 20 |w and lo|ve. The |
|00001f20| 41 50 49 20 69 73 20 77 | 65 6c 6c 20 64 65 66 69 |API is w|ell defi|
|00001f30| 6e 65 64 2c 20 63 6f 6d | 70 65 6c 6c 69 6e 67 2c |ned, com|pelling,|
|00001f40| 20 61 6e 64 20 65 61 73 | 79 20 74 6f 20 75 73 65 | and eas|y to use|
|00001f50| d1 6e 6f 20 6d 75 73 73 | 2c 20 6e 6f 20 66 75 73 |.no muss|, no fus|
|00001f60| 73 2e 20 46 6f 72 20 74 | 68 6f 73 65 20 77 68 6f |s. For t|hose who|
|00001f70| 20 6e 65 65 64 20 74 6f | 20 67 65 74 20 64 6f 77 | need to| get dow|
|00001f80| 6e 20 61 6e 64 20 64 69 | 72 74 79 2c 20 74 68 65 |n and di|rty, the|
|00001f90| 20 54 68 72 65 61 64 20 | 4d 61 6e 61 67 65 72 20 | Thread |Manager |
|00001fa0| 70 72 6f 76 69 64 65 73 | 20 72 6f 75 74 69 6e 65 |provides| routine|
|00001fb0| 73 20 74 6f 20 6d 6f 64 | 69 66 79 20 74 68 65 20 |s to mod|ify the |
|00001fc0| 62 65 68 61 76 69 6f 72 | 20 6f 66 20 74 68 65 20 |behavior| of the |
|00001fd0| 73 63 68 65 64 75 6c 69 | 6e 67 20 6d 65 63 68 61 |scheduli|ng mecha|
|00001fe0| 6e 69 73 6d 20 61 6e 64 | 20 63 6f 6e 74 65 78 74 |nism and| context|
|00001ff0| 20 73 77 69 74 63 68 69 | 6e 67 20 63 6f 64 65 2e | switchi|ng code.|
|00002000| 0d 20 0d 09 54 68 65 20 | 41 50 49 20 67 6f 65 73 |. ..The |API goes|
|00002010| 20 74 68 72 6f 75 67 68 | 20 61 20 73 69 6e 67 6c | through| a singl|
|00002020| 65 20 74 72 61 70 3a 20 | 54 68 72 65 61 64 44 69 |e trap: |ThreadDi|
|00002030| 73 70 61 74 63 68 2e 20 | 20 50 61 72 61 6d 65 74 |spatch. | Paramet|
|00002040| 65 72 73 20 61 72 65 20 | 74 72 61 6e 73 66 65 72 |ers are |transfer|
|00002050| 72 65 64 20 6f 6e 20 74 | 68 65 20 73 74 61 63 6b |red on t|he stack|
|00002060| 20 61 6e 64 20 61 6c 6c | 20 72 6f 75 74 69 6e 65 | and all| routine|
|00002070| 73 20 72 65 74 75 72 6e | 20 61 6e 20 4f 53 45 72 |s return| an OSEr|
|00002080| 72 20 61 73 20 74 68 65 | 69 72 20 72 65 73 75 6c |r as the|ir resul|
|00002090| 74 2e 20 54 68 65 20 74 | 72 61 70 20 64 69 73 70 |t. The t|rap disp|
|000020a0| 61 74 63 68 20 6e 75 6d | 62 65 72 73 20 68 61 76 |atch num|bers hav|
|000020b0| 65 20 62 6f 74 68 20 61 | 20 70 61 72 61 6d 65 74 |e both a| paramet|
|000020c0| 65 72 20 73 69 7a 65 20 | 61 6e 64 20 61 20 72 6f |er size |and a ro|
|000020d0| 75 74 69 6e 65 20 6e 75 | 6d 62 65 72 20 65 6e 63 |utine nu|mber enc|
|000020e0| 6f 64 65 64 20 69 6e 20 | 74 68 65 6d 20 77 68 69 |oded in |them whi|
|000020f0| 63 68 20 61 6c 6c 6f 77 | 73 20 6f 6c 64 65 72 20 |ch allow|s older |
|00002100| 76 65 72 73 69 6f 6e 73 | 20 6f 66 20 74 68 65 20 |versions| of the |
|00002110| 54 68 72 65 61 64 20 4d | 61 6e 61 67 65 72 20 74 |Thread M|anager t|
|00002120| 6f 20 73 61 66 65 6c 79 | 20 72 65 6a 65 63 74 20 |o safely| reject |
|00002130| 63 61 6c 6c 73 20 69 6d | 70 6c 65 6d 65 6e 74 65 |calls im|plemente|
|00002140| 64 20 6f 6e 6c 79 20 62 | 79 20 6e 65 77 65 72 20 |d only b|y newer |
|00002150| 76 65 72 73 69 6f 6e 73 | 2e 20 41 20 70 61 72 61 |versions|. A para|
|00002160| 6d 45 72 72 20 69 73 20 | 72 65 74 75 72 6e 65 64 |mErr is |returned|
|00002170| 20 66 6f 72 20 63 61 6c | 6c 73 20 6e 6f 74 20 69 | for cal|ls not i|
|00002180| 6d 70 6c 65 6d 65 6e 74 | 65 64 2e 0d 09 54 68 65 |mplement|ed...The|
|00002190| 20 54 68 72 65 61 64 73 | 4c 69 62 20 69 73 20 61 | Threads|Lib is a|
|000021a0| 20 73 68 61 72 65 64 20 | 6c 69 62 72 61 72 79 20 | shared |library |
|000021b0| 73 6f 20 74 68 65 72 65 | 20 69 73 20 6e 6f 20 70 |so there| is no p|
|000021c0| 65 72 66 6f 72 6d 61 6e | 63 65 20 68 69 74 20 64 |erforman|ce hit d|
|000021d0| 75 65 20 74 6f 20 61 20 | 74 72 61 70 20 63 61 6c |ue to a |trap cal|
|000021e0| 6c 2c 20 77 68 65 6e 20 | 75 73 69 6e 67 20 74 68 |l, when |using th|
|000021f0| 65 20 54 68 72 65 61 64 | 20 4d 61 6e 61 67 65 72 |e Thread| Manager|
|00002200| 20 41 50 49 2e 20 20 54 | 68 65 72 65 20 69 73 20 | API. T|here is |
|00002210| 61 20 64 69 73 74 69 6e | 63 74 69 6f 6e 20 62 65 |a distin|ction be|
|00002220| 74 77 65 65 6e 20 36 38 | 30 78 30 20 74 68 72 65 |tween 68|0x0 thre|
|00002230| 61 64 73 20 61 6e 64 20 | 70 6f 77 65 72 20 74 68 |ads and |power th|
|00002240| 72 65 61 64 73 2e 20 20 | 41 20 36 38 30 78 30 20 |reads. |A 680x0 |
|00002250| 61 70 70 6c 69 63 61 74 | 69 6f 6e 20 6d 61 79 20 |applicat|ion may |
|00002260| 6f 6e 6c 79 20 75 73 65 | 20 36 38 30 78 30 20 74 |only use| 680x0 t|
|00002270| 68 72 65 61 64 73 2c 20 | 61 6e 64 20 70 6f 77 65 |hreads, |and powe|
|00002280| 72 20 61 70 70 6c 69 63 | 61 74 69 6f 6e 73 20 6d |r applic|ations m|
|00002290| 61 79 20 6f 6e 6c 79 20 | 75 73 65 20 70 6f 77 65 |ay only |use powe|
|000022a0| 72 20 74 68 72 65 61 64 | 73 2e 20 20 4d 69 78 69 |r thread|s. Mixi|
|000022b0| 6e 67 20 74 68 72 65 61 | 64 20 74 79 70 65 73 20 |ng threa|d types |
|000022c0| 28 70 6f 77 65 72 20 6f | 72 20 36 38 30 78 30 29 |(power o|r 680x0)|
|000022d0| 20 77 69 74 68 69 6e 20 | 61 6e 20 61 70 70 6c 69 | within |an appli|
|000022e0| 63 61 74 69 6f 6e 20 74 | 79 70 65 20 28 70 6f 77 |cation t|ype (pow|
|000022f0| 65 72 20 6f 72 20 36 38 | 30 78 30 29 20 69 73 20 |er or 68|0x0) is |
|00002300| 63 6f 6e 73 69 64 65 72 | 65 64 20 61 20 70 72 6f |consider|ed a pro|
|00002310| 67 72 61 6d 6d 69 6e 67 | 20 65 72 72 6f 72 20 61 |gramming| error a|
|00002320| 6e 64 20 69 73 20 6e 6f | 74 20 73 75 70 70 6f 72 |nd is no|t suppor|
|00002330| 74 65 64 2e 0d 50 65 72 | 66 6f 72 6d 61 6e 63 65 |ted..Per|formance|
|00002340| 0d 09 54 68 65 20 63 6f | 6e 74 65 78 74 20 73 77 |..The co|ntext sw|
|00002350| 69 74 63 68 20 74 69 6d | 65 20 66 6f 72 20 61 6e |itch tim|e for an|
|00002360| 20 69 6e 64 69 76 69 64 | 75 61 6c 20 74 68 72 65 | individ|ual thre|
|00002370| 61 64 20 69 73 20 6e 65 | 67 6c 69 67 69 62 6c 65 |ad is ne|gligible|
|00002380| 20 64 75 65 20 74 6f 20 | 74 68 65 20 6d 69 6e 69 | due to |the mini|
|00002390| 6d 61 6c 20 63 6f 6e 74 | 65 78 74 20 72 65 71 75 |mal cont|ext requ|
|000023a0| 69 72 65 64 20 66 6f 72 | 20 61 20 73 77 69 74 63 |ired for| a switc|
|000023b0| 68 2e 20 54 68 65 20 64 | 65 66 61 75 6c 74 20 63 |h. The d|efault c|
|000023c0| 6f 6e 74 65 78 74 20 73 | 61 76 65 64 20 62 79 20 |ontext s|aved by |
|000023d0| 74 68 65 20 54 68 72 65 | 61 64 20 4d 61 6e 61 67 |the Thre|ad Manag|
|000023e0| 65 72 20 69 6e 63 6c 75 | 64 65 73 20 61 6c 6c 20 |er inclu|des all |
|000023f0| 70 72 6f 63 65 73 73 6f | 72 20 64 61 74 61 2c 20 |processo|r data, |
|00002400| 61 64 64 72 65 73 73 2c | 20 61 6e 64 20 46 50 55 |address,| and FPU|
|00002410| 20 28 77 68 65 6e 20 72 | 65 71 75 69 72 65 64 29 | (when r|equired)|
|00002420| 20 72 65 67 69 73 74 65 | 72 73 2e 20 54 68 65 20 | registe|rs. The |
|00002430| 74 68 72 65 61 64 20 63 | 6f 6e 74 65 78 74 20 6d |thread c|ontext m|
|00002440| 61 79 20 62 65 20 65 6e | 68 61 6e 63 65 64 20 62 |ay be en|hanced b|
|00002450| 79 20 74 68 65 20 61 70 | 70 6c 69 63 61 74 69 6f |y the ap|plicatio|
|00002460| 6e 20 28 74 6f 20 69 6e | 63 6c 75 64 65 20 61 70 |n (to in|clude ap|
|00002470| 70 6c 69 63 61 74 69 6f | 6e 20 73 70 65 63 69 66 |plicatio|n specif|
|00002480| 69 63 20 63 6f 6e 74 65 | 78 74 29 20 77 68 69 63 |ic conte|xt) whic|
|00002490| 68 20 77 69 6c 6c 20 69 | 6e 63 72 65 61 73 65 20 |h will i|ncrease |
|000024a0| 63 6f 6e 74 65 78 74 20 | 73 77 69 74 63 68 20 74 |context |switch t|
|000024b0| 69 6d 65 73 20 28 79 6f | 75 72 20 6d 69 6c 65 61 |imes (yo|ur milea|
|000024c0| 67 65 20 6d 61 79 20 76 | 61 72 79 29 2e 0d 09 42 |ge may v|ary)...B|
|000024d0| 6f 74 68 20 63 6f 6f 70 | 65 72 61 74 69 76 65 20 |oth coop|erative |
|000024e0| 61 6e 64 20 70 72 65 65 | 6d 70 74 69 76 65 20 74 |and pree|mptive t|
|000024f0| 68 72 65 61 64 73 20 61 | 72 65 20 65 6c 69 67 69 |hreads a|re eligi|
|00002500| 62 6c 65 20 66 6f 72 20 | 65 78 65 63 75 74 69 6f |ble for |executio|
|00002510| 6e 20 6f 6e 6c 79 20 77 | 68 65 6e 20 74 68 65 20 |n only w|hen the |
|00002520| 61 70 70 6c 69 63 61 74 | 69 6f 6e 20 69 73 20 73 |applicat|ion is s|
|00002530| 77 69 74 63 68 65 64 20 | 69 6e 20 62 79 20 74 68 |witched |in by th|
|00002540| 65 20 70 72 6f 63 65 73 | 73 20 6d 61 6e 61 67 65 |e proces|s manage|
|00002550| 72 2e 20 49 6e 20 74 68 | 69 73 20 77 61 79 2c 20 |r. In th|is way, |
|00002560| 61 6c 6c 20 74 68 72 65 | 61 64 73 20 68 61 76 65 |all thre|ads have|
|00002570| 20 74 68 65 20 66 75 6c | 6c 20 61 70 70 6c 69 63 | the ful|l applic|
|00002580| 61 74 69 6f 6e 20 63 6f | 6e 74 65 78 74 20 61 76 |ation co|ntext av|
|00002590| 61 69 6c 61 62 6c 65 20 | 74 6f 20 74 68 65 6d 20 |ailable |to them |
|000025a0| 61 6e 64 20 61 72 65 20 | 65 78 65 63 75 74 65 64 |and are |executed|
|000025b0| 20 6f 6e 6c 79 20 77 68 | 65 6e 20 74 68 65 20 61 | only wh|en the a|
|000025c0| 70 70 6c 69 63 61 74 69 | 6f 6e 20 67 65 74 73 20 |pplicati|on gets |
|000025d0| 74 69 6d 65 20 74 6f 20 | 72 75 6e 2e 20 0d 09 54 |time to |run. ..T|
|000025e0| 68 65 20 69 6e 74 65 72 | 6c 65 61 76 65 20 64 65 |he inter|leave de|
|000025f0| 73 69 67 6e 20 6f 66 20 | 6f 6e 65 20 63 6f 6f 70 |sign of |one coop|
|00002600| 65 72 61 74 69 76 65 20 | 63 6f 6e 74 65 78 74 20 |erative |context |
|00002610| 62 65 74 77 65 65 6e 20 | 65 76 65 72 79 20 70 72 |between |every pr|
|00002620| 65 65 6d 70 74 69 76 65 | 20 63 6f 6e 74 65 78 74 |eemptive| context|
|00002630| 20 67 75 61 72 61 6e 74 | 65 65 73 20 74 68 61 74 | guarant|ees that|
|00002640| 20 74 68 72 65 61 64 73 | 20 77 68 69 63 68 20 63 | threads| which c|
|00002650| 61 6e 20 75 73 65 20 74 | 68 65 20 54 6f 6f 6c 62 |an use t|he Toolb|
|00002660| 6f 78 20 28 63 6f 6f 70 | 65 72 61 74 69 76 65 20 |ox (coop|erative |
|00002670| 74 68 72 65 61 64 73 29 | 20 77 69 6c 6c 20 62 65 |threads)| will be|
|00002680| 20 67 69 76 65 6e 20 43 | 50 55 20 74 69 6d 65 20 | given C|PU time |
|00002690| 74 6f 20 65 6e 68 61 6e | 63 65 20 75 73 65 72 20 |to enhan|ce user |
|000026a0| 69 6e 74 65 72 66 61 63 | 65 20 70 65 72 66 6f 72 |interfac|e perfor|
|000026b0| 6d 61 6e 63 65 2e 0d 50 | 61 72 74 20 32 3a 20 46 |mance..P|art 2: F|
|000026c0| 55 4e 43 54 49 4f 4e 41 | 4c 20 53 50 45 43 49 46 |UNCTIONA|L SPECIF|
|000026d0| 49 43 41 54 49 4f 4e 53 | 0d 46 65 61 74 75 72 65 |ICATIONS|.Feature|
|000026e0| 73 20 4f 76 65 72 76 69 | 65 77 0d 09 50 65 72 2d |s Overvi|ew..Per-|
|000026f0| 61 70 70 6c 69 63 61 74 | 69 6f 6e 20 74 68 72 65 |applicat|ion thre|
|00002700| 61 64 20 69 6e 69 74 69 | 61 6c 69 7a 61 74 69 6f |ad initi|alizatio|
|00002710| 6e 20 69 73 20 63 6f 6d | 70 6c 65 74 65 64 20 70 |n is com|pleted p|
|00002720| 72 69 6f 72 20 74 6f 20 | 74 68 65 20 65 6e 74 65 |rior to |the ente|
|00002730| 72 69 6e 67 20 74 68 65 | 20 61 70 70 6c 69 63 61 |ring the| applica|
|00002740| 74 69 6f 6e 2c 20 77 68 | 69 63 68 20 61 6c 6c 6f |tion, wh|ich allo|
|00002750| 77 73 20 20 61 70 70 6c | 69 63 61 74 69 6f 6e 73 |ws appl|ications|
|00002760| 20 74 6f 20 62 65 67 69 | 6e 20 75 73 69 6e 67 20 | to begi|n using |
|00002770| 74 68 65 20 54 68 72 65 | 61 64 20 4d 61 6e 61 67 |the Thre|ad Manag|
|00002780| 65 72 20 66 75 6e 63 74 | 69 6f 6e 73 20 61 73 20 |er funct|ions as |
|00002790| 73 6f 6f 6e 20 61 73 20 | 74 68 65 69 72 20 6d 61 |soon as |their ma|
|000027a0| 69 6e 20 72 6f 75 74 69 | 6e 65 20 62 65 67 69 6e |in routi|ne begin|
|000027b0| 73 20 65 78 65 63 75 74 | 69 6f 6e 2e 20 54 68 72 |s execut|ion. Thr|
|000027c0| 65 61 64 20 63 6c 65 61 | 6e 20 75 70 20 69 73 20 |ead clea|n up is |
|000027d0| 6e 6f 74 20 72 65 71 75 | 69 72 65 64 20 61 73 20 |not requ|ired as |
|000027e0| 74 68 69 73 20 69 73 20 | 64 6f 6e 65 20 62 79 20 |this is |done by |
|000027f0| 74 68 65 20 54 68 72 65 | 61 64 20 4d 61 6e 61 67 |the Thre|ad Manag|
|00002800| 65 72 20 61 74 20 61 70 | 70 6c 69 63 61 74 69 6f |er at ap|plicatio|
|00002810| 6e 20 74 65 72 6d 69 6e | 61 74 69 6f 6e 20 74 69 |n termin|ation ti|
|00002820| 6d 65 2e 0d 09 41 70 70 | 6c 69 63 61 74 69 6f 6e |me...App|lication|
|00002830| 73 20 61 72 65 20 70 72 | 6f 76 69 64 65 64 20 77 |s are pr|ovided w|
|00002840| 69 74 68 20 67 65 6e 65 | 72 61 6c 20 70 75 72 70 |ith gene|ral purp|
|00002850| 6f 73 65 20 72 6f 75 74 | 69 6e 65 73 20 66 6f 72 |ose rout|ines for|
|00002860| 20 74 68 72 65 61 64 20 | 70 6f 6f 6c 20 63 72 65 | thread |pool cre|
|00002870| 61 74 69 6f 6e 2c 20 63 | 6f 75 6e 74 69 6e 67 2c |ation, c|ounting,|
|00002880| 20 61 6c 6c 6f 63 61 74 | 69 6f 6e 20 61 6e 64 20 | allocat|ion and |
|00002890| 64 65 6c 65 74 69 6f 6e | 2e 20 42 61 73 69 63 20 |deletion|. Basic |
|000028a0| 73 63 68 65 64 75 6c 69 | 6e 67 20 72 6f 75 74 69 |scheduli|ng routi|
|000028b0| 6e 65 73 20 61 72 65 20 | 70 72 6f 76 69 64 65 64 |nes are |provided|
|000028c0| 20 74 6f 20 61 63 71 75 | 69 72 65 20 74 68 65 20 | to acqu|ire the |
|000028d0| 49 44 20 6f 66 20 74 68 | 65 20 63 75 72 72 65 6e |ID of th|e curren|
|000028e0| 74 6c 79 20 65 78 65 63 | 75 74 69 6e 67 20 74 68 |tly exec|uting th|
|000028f0| 72 65 61 64 20 61 6e 64 | 20 74 6f 20 79 69 65 6c |read and| to yiel|
|00002900| 64 20 74 6f 20 61 6e 79 | 20 74 68 72 65 61 64 2e |d to any| thread.|
|00002910| 20 50 72 65 65 6d 70 74 | 69 76 65 20 74 68 72 65 | Preempt|ive thre|
|00002920| 61 64 20 73 63 68 65 64 | 75 6c 69 6e 67 20 72 6f |ad sched|uling ro|
|00002930| 75 74 69 6e 65 73 20 61 | 6c 6c 6f 77 20 61 20 74 |utines a|llow a t|
|00002940| 68 72 65 61 64 20 74 6f | 20 64 69 73 61 62 6c 65 |hread to| disable|
|00002950| 20 70 72 65 65 6d 70 74 | 69 6f 6e 20 64 75 72 69 | preempt|ion duri|
|00002960| 6e 67 20 63 72 69 74 69 | 63 61 6c 20 73 65 63 74 |ng criti|cal sect|
|00002970| 69 6f 6e 73 20 6f 66 20 | 63 6f 64 65 2e 20 41 64 |ions of |code. Ad|
|00002980| 76 61 6e 63 65 64 20 73 | 63 68 65 64 75 6c 69 6e |vanced s|chedulin|
|00002990| 67 20 72 6f 75 74 69 6e | 65 73 20 67 69 76 65 20 |g routin|es give |
|000029a0| 74 68 65 20 61 62 69 6c | 69 74 79 20 74 6f 20 79 |the abil|ity to y|
|000029b0| 69 65 6c 64 20 74 6f 20 | 61 20 70 61 72 74 69 63 |ield to |a partic|
|000029c0| 75 6c 61 72 20 74 68 72 | 65 61 64 2c 20 61 6e 64 |ular thr|ead, and|
|000029d0| 20 67 65 74 20 26 20 73 | 65 74 20 74 68 65 20 73 | get & s|et the s|
|000029e0| 74 61 74 65 20 6f 66 20 | 61 6e 79 20 74 68 72 65 |tate of |any thre|
|000029f0| 61 64 2e 20 4d 65 63 68 | 61 6e 69 73 6d 73 20 61 |ad. Mech|anisms a|
|00002a00| 72 65 20 61 6c 73 6f 20 | 70 72 6f 76 69 64 65 64 |re also |provided|
|00002a10| 20 74 6f 20 63 75 73 74 | 6f 6d 69 7a 65 20 74 68 | to cust|omize th|
|00002a20| 65 20 74 68 72 65 61 64 | 20 73 63 68 65 64 75 6c |e thread| schedul|
|00002a30| 65 72 20 61 6e 64 20 61 | 64 64 20 63 75 73 74 6f |er and a|dd custo|
|00002a40| 6d 20 63 6f 6e 74 65 78 | 74 20 73 77 69 74 63 68 |m contex|t switch|
|00002a50| 69 6e 67 20 72 6f 75 74 | 69 6e 65 73 2e 0d 53 6f |ing rout|ines..So|
|00002a60| 66 74 77 61 72 65 20 44 | 65 73 69 67 6e 20 26 20 |ftware D|esign & |
|00002a70| 54 65 63 68 6e 69 63 61 | 6c 20 44 65 73 63 72 69 |Technica|l Descri|
|00002a80| 70 74 69 6f 6e 0d 09 49 | 6e 73 74 61 6c 6c 61 74 |ption..I|nstallat|
|00002a90| 69 6f 6e 3a 20 44 75 72 | 69 6e 67 20 73 79 73 74 |ion: Dur|ing syst|
|00002aa0| 65 6d 20 73 74 61 72 74 | 75 70 2c 20 74 68 65 20 |em start|up, the |
|00002ab0| 54 68 72 65 61 64 20 4d | 61 6e 61 67 65 72 20 69 |Thread M|anager i|
|00002ac0| 73 20 69 6e 73 74 61 6c | 6c 65 64 20 69 6e 74 6f |s instal|led into|
|00002ad0| 20 74 68 65 20 73 79 73 | 74 65 6d 20 61 6e 64 20 | the sys|tem and |
|00002ae0| 73 65 74 73 20 75 70 20 | 73 79 73 74 65 6d 2d 77 |sets up |system-w|
|00002af0| 69 64 65 20 67 6c 6f 62 | 61 6c 73 20 61 6e 64 20 |ide glob|als and |
|00002b00| 70 61 74 63 68 20 63 6f | 64 65 2e 20 20 0d 20 09 |patch co|de. . .|
|00002b10| 49 6e 69 74 69 61 6c 69 | 7a 61 74 69 6f 6e 3a 20 |Initiali|zation: |
|00002b20| 50 65 72 2d 61 70 70 6c | 69 63 61 74 69 6f 6e 20 |Per-appl|ication |
|00002b30| 69 6e 69 74 69 61 6c 69 | 7a 61 74 69 6f 6e 20 69 |initiali|zation i|
|00002b40| 73 20 64 6f 6e 65 20 70 | 72 69 6f 72 20 74 6f 20 |s done p|rior to |
|00002b50| 65 6e 74 65 72 69 6e 67 | 20 74 68 65 20 61 70 70 |entering| the app|
|00002b60| 6c 69 63 61 74 69 6f 6e | 2e 20 54 68 69 73 20 61 |lication|. This a|
|00002b70| 6c 6c 6f 77 73 20 61 70 | 70 6c 69 63 61 74 69 6f |llows ap|plicatio|
|00002b80| 6e 73 20 74 6f 20 74 61 | 6b 65 20 61 64 76 61 6e |ns to ta|ke advan|
|00002b90| 74 61 67 65 20 6f 66 20 | 74 68 65 20 54 68 72 65 |tage of |the Thre|
|00002ba0| 61 64 20 4d 61 6e 61 67 | 65 72 20 66 75 6e 63 74 |ad Manag|er funct|
|00002bb0| 69 6f 6e 73 20 61 73 20 | 73 6f 6f 6e 20 61 73 20 |ions as |soon as |
|00002bc0| 74 68 65 79 20 62 65 67 | 69 6e 20 65 78 65 63 75 |they beg|in execu|
|00002bd0| 74 69 6f 6e 20 6f 66 20 | 74 68 65 20 6d 61 69 6e |tion of |the main|
|00002be0| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 20 74 68 72 | applica|tion thr|
|00002bf0| 65 61 64 2e 20 49 6d 70 | 6f 72 74 61 6e 74 3a 20 |ead. Imp|ortant: |
|00002c00| 54 68 65 20 4d 65 6d 6f | 72 79 20 4d 61 6e 61 67 |The Memo|ry Manag|
|00002c10| 65 72 20 72 6f 75 74 69 | 6e 65 20 4d 61 78 41 70 |er routi|ne MaxAp|
|00002c20| 70 6c 5a 6f 6e 65 20 6d | 75 73 74 20 62 65 20 63 |plZone m|ust be c|
|00002c30| 61 6c 6c 65 64 20 62 65 | 66 6f 72 65 20 61 6e 79 |alled be|fore any|
|00002c40| 20 74 68 72 65 61 64 20 | 6f 74 68 65 72 20 74 68 | thread |other th|
|00002c50| 61 6e 20 74 68 65 20 6d | 61 69 6e 20 61 70 70 6c |an the m|ain appl|
|00002c60| 69 63 61 74 69 6f 6e 20 | 74 68 72 65 61 64 20 61 |ication |thread a|
|00002c70| 6c 6c 6f 63 61 74 65 73 | 20 6d 65 6d 6f 72 79 2c |llocates| memory,|
|00002c80| 20 6f 72 20 63 61 75 73 | 65 73 20 6d 65 6d 6f 72 | or caus|es memor|
|00002c90| 79 20 74 6f 20 62 65 20 | 61 6c 6c 6f 63 61 74 65 |y to be |allocate|
|00002ca0| 64 20 28 73 65 65 20 74 | 68 65 20 43 6f 6e 73 74 |d (see t|he Const|
|00002cb0| 72 61 69 6e 74 73 2c 20 | 47 6f 74 63 68 61 73 20 |raints, |Gotchas |
|00002cc0| 26 20 42 75 67 73 20 73 | 65 63 74 69 6f 6e 20 66 |& Bugs s|ection f|
|00002cd0| 6f 72 20 6d 6f 72 65 20 | 69 6e 66 6f 72 6d 61 74 |or more |informat|
|00002ce0| 69 6f 6e 29 2e 0d 09 43 | 6c 65 61 6e 75 70 3a 20 |ion)...C|leanup: |
|00002cf0| 20 54 68 65 20 54 68 72 | 65 61 64 20 4d 61 6e 61 | The Thr|ead Mana|
|00002d00| 67 65 72 20 69 73 20 63 | 61 6c 6c 65 64 20 62 79 |ger is c|alled by|
|00002d10| 20 74 68 65 20 50 72 6f | 63 65 73 73 20 4d 61 6e | the Pro|cess Man|
|00002d20| 61 67 65 72 20 77 68 65 | 6e 20 61 6e 20 61 70 70 |ager whe|n an app|
|00002d30| 6c 69 63 61 74 69 6f 6e | 20 74 65 72 6d 69 6e 61 |lication| termina|
|00002d40| 74 65 73 2e 20 20 54 68 | 69 73 20 67 69 76 65 73 |tes. Th|is gives|
|00002d50| 20 74 68 65 20 54 68 72 | 65 61 64 20 4d 61 6e 61 | the Thr|ead Mana|
|00002d60| 67 65 72 20 61 20 63 68 | 61 6e 63 65 20 74 6f 20 |ger a ch|ance to |
|00002d70| 74 65 61 72 20 64 6f 77 | 6e 20 74 68 65 20 74 68 |tear dow|n the th|
|00002d80| 72 65 61 64 69 6e 67 20 | 6d 65 63 68 61 6e 69 73 |reading |mechanis|
|00002d90| 6d 20 66 6f 72 20 74 68 | 65 20 61 70 70 6c 69 63 |m for th|e applic|
|00002da0| 61 74 69 6f 6e 20 61 6e | 64 20 72 65 74 75 72 6e |ation an|d return|
|00002db0| 20 61 70 70 72 6f 70 72 | 69 61 74 65 20 73 79 73 | appropr|iate sys|
|00002dc0| 74 65 6d 20 72 65 73 6f | 75 72 63 65 73 2c 20 73 |tem reso|urces, s|
|00002dd0| 75 63 68 20 61 73 20 6d | 65 6d 6f 72 79 2e 0d 09 |uch as m|emory...|
|00002de0| 43 6f 6e 74 72 6f 6c 3a | 20 54 68 65 20 54 68 72 |Control:| The Thr|
|00002df0| 65 61 64 20 4d 61 6e 61 | 67 65 72 20 67 65 74 73 |ead Mana|ger gets|
|00002e00| 20 63 6f 6e 74 72 6f 6c | 20 69 6e 20 74 68 72 65 | control| in thre|
|00002e10| 65 20 77 61 79 73 2e 20 | 20 54 68 65 20 73 74 72 |e ways. | The str|
|00002e20| 61 69 67 68 74 66 6f 72 | 77 61 72 64 20 77 61 79 |aightfor|ward way|
|00002e30| 20 69 73 20 74 68 72 6f | 75 67 68 20 41 50 49 20 | is thro|ugh API |
|00002e40| 63 61 6c 6c 73 20 6d 61 | 64 65 20 62 79 20 61 20 |calls ma|de by a |
|00002e50| 74 68 72 65 61 64 65 64 | 20 61 70 70 6c 69 63 61 |threaded| applica|
|00002e60| 74 69 6f 6e 2e 20 41 6c | 6c 20 63 61 6c 6c 73 20 |tion. Al|l calls |
|00002e70| 74 6f 20 74 68 65 20 54 | 68 72 65 61 64 20 4d 61 |to the T|hread Ma|
|00002e80| 6e 61 67 65 72 20 61 72 | 65 20 6d 61 64 65 20 74 |nager ar|e made t|
|00002e90| 68 72 6f 75 67 68 20 74 | 68 65 20 74 72 61 70 20 |hrough t|he trap |
|00002ea0| 54 68 72 65 61 64 44 69 | 73 70 61 74 63 68 20 28 |ThreadDi|spatch (|
|00002eb0| 30 78 41 42 46 32 29 2e | 20 54 68 65 20 6c 65 73 |0xABF2).| The les|
|00002ec0| 73 20 73 74 72 61 69 67 | 68 74 66 6f 72 77 61 72 |s straig|htforwar|
|00002ed0| 64 20 77 61 79 20 69 73 | 20 76 69 61 20 68 61 72 |d way is| via har|
|00002ee0| 64 77 61 72 65 20 69 6e | 74 65 72 72 75 70 74 73 |dware in|terrupts|
|00002ef0| 20 74 6f 20 67 69 76 65 | 20 74 68 65 20 54 68 72 | to give| the Thr|
|00002f00| 65 61 64 20 4d 61 6e 61 | 67 65 72 20 70 72 65 65 |ead Mana|ger pree|
|00002f10| 6d 70 74 69 6f 6e 20 73 | 63 68 65 64 75 6c 65 72 |mption s|cheduler|
|00002f20| 20 61 20 63 68 61 6e 63 | 65 20 74 6f 20 72 65 73 | a chanc|e to res|
|00002f30| 63 68 65 64 75 6c 65 20 | 70 72 65 65 6d 70 74 69 |chedule |preempti|
|00002f40| 76 65 20 74 68 72 65 61 | 64 73 2e 20 46 6f 72 20 |ve threa|ds. For |
|00002f50| 70 6f 77 65 72 20 61 70 | 70 6c 69 63 61 74 69 6f |power ap|plicatio|
|00002f60| 6e 73 2c 20 74 68 65 20 | 54 68 72 65 61 64 20 4d |ns, the |Thread M|
|00002f70| 61 6e 61 67 65 72 20 69 | 73 20 63 61 6c 6c 65 64 |anager i|s called|
|00002f80| 20 74 68 72 6f 75 67 68 | 20 74 68 65 20 75 73 65 | through| the use|
|00002f90| 20 6f 66 20 6c 69 62 72 | 61 72 79 20 63 61 6c 6c | of libr|ary call|
|00002fa0| 73 20 74 6f 20 74 68 65 | 20 54 68 72 65 61 64 20 |s to the| Thread |
|00002fb0| 4d 61 6e 61 67 65 72 20 | 73 68 61 72 65 64 20 6c |Manager |shared l|
|00002fc0| 69 62 72 61 72 79 2e 0d | 09 54 68 72 65 61 64 20 |ibrary..|.Thread |
|00002fd0| 54 79 70 65 73 3a 20 54 | 68 65 20 54 68 72 65 61 |Types: T|he Threa|
|00002fe0| 64 20 4d 61 6e 61 67 65 | 72 20 61 6c 6c 6f 77 73 |d Manage|r allows|
|00002ff0| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 73 20 74 6f | applica|tions to|
|00003000| 20 63 72 65 61 74 65 20 | 61 6e 64 20 62 65 67 69 | create |and begi|
|00003010| 6e 20 65 78 65 63 75 74 | 69 6f 6e 20 6f 66 20 74 |n execut|ion of t|
|00003020| 77 6f 20 74 79 70 65 73 | 20 6f 66 20 74 68 72 65 |wo types| of thre|
|00003030| 61 64 73 3a 20 63 6f 6f | 70 65 72 61 74 69 76 65 |ads: coo|perative|
|00003040| 20 61 6e 64 20 70 72 65 | 65 6d 70 74 69 76 65 2e | and pre|emptive.|
|00003050| 20 43 6f 6f 70 65 72 61 | 74 69 76 65 20 74 68 72 | Coopera|tive thr|
|00003060| 65 61 64 73 20 6d 61 6b | 65 20 75 73 65 20 6f 66 |eads mak|e use of|
|00003070| 20 61 20 63 6f 6f 70 65 | 72 61 74 69 76 65 20 73 | a coope|rative s|
|00003080| 63 68 65 64 75 6c 69 6e | 67 20 6d 6f 64 65 6c 20 |chedulin|g model |
|00003090| 61 6e 64 20 63 61 6e 20 | 6d 61 6b 65 20 75 73 65 |and can |make use|
|000030a0| 20 6f 66 20 61 6c 6c 20 | 54 6f 6f 6c 62 6f 78 20 | of all |Toolbox |
|000030b0| 61 6e 64 20 6f 70 65 72 | 61 74 69 6e 67 20 73 79 |and oper|ating sy|
|000030c0| 73 74 65 6d 20 66 75 6e | 63 74 69 6f 6e 73 2e 20 |stem fun|ctions. |
|000030d0| 54 68 69 73 20 74 79 70 | 65 20 6f 66 20 74 68 72 |This typ|e of thr|
|000030e0| 65 61 64 20 68 61 73 20 | 61 6c 6c 20 74 68 65 20 |ead has |all the |
|000030f0| 72 69 67 68 74 73 20 61 | 6e 64 20 70 72 69 76 69 |rights a|nd privi|
|00003100| 6c 65 67 65 73 20 6f 66 | 20 72 65 67 75 6c 61 72 |leges of| regular|
|00003110| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 20 63 6f 64 | applica|tion cod|
|00003120| 65 2c 20 77 68 69 63 68 | 20 69 6e 63 6c 75 64 65 |e, which| include|
|00003130| 73 20 74 68 65 20 75 73 | 65 20 61 6c 6c 20 54 6f |s the us|e all To|
|00003140| 6f 6c 62 6f 78 20 61 6e | 64 20 4f 53 20 66 65 61 |olbox an|d OS fea|
|00003150| 74 75 72 65 73 20 61 76 | 61 69 6c 61 62 6c 65 20 |tures av|ailable |
|00003160| 74 6f 20 61 70 70 6c 69 | 63 61 74 69 6f 6e 73 20 |to appli|cations |
|00003170| 74 6f 64 61 79 2e 20 20 | 46 6f 72 20 36 38 30 78 |today. |For 680x|
|00003180| 30 20 61 70 70 6c 69 63 | 61 74 69 6f 6e 73 20 6f |0 applic|ations o|
|00003190| 6e 79 2c 20 70 72 65 65 | 6d 70 74 69 76 65 20 74 |ny, pree|mptive t|
|000031a0| 68 72 65 61 64 73 20 6d | 61 6b 65 20 75 73 65 20 |hreads m|ake use |
|000031b0| 6f 66 20 61 20 70 72 65 | 65 6d 70 74 69 76 65 20 |of a pre|emptive |
|000031c0| 73 63 68 65 64 75 6c 69 | 6e 67 20 6d 6f 64 65 6c |scheduli|ng model|
|000031d0| 20 61 6e 64 20 6d 61 79 | 20 6e 6f 74 20 6d 61 6b | and may| not mak|
|000031e0| 65 20 75 73 65 20 6f 66 | 20 54 6f 6f 6c 62 6f 78 |e use of| Toolbox|
|000031f0| 20 6f 72 20 6f 70 65 72 | 61 74 69 6e 67 20 73 79 | or oper|ating sy|
|00003200| 73 74 65 6d 20 73 65 72 | 76 69 63 65 73 3b 20 6f |stem ser|vices; o|
|00003210| 6e 6c 79 20 74 68 6f 73 | 65 20 54 6f 6f 6c 62 6f |nly thos|e Toolbo|
|00003220| 78 20 6f 72 20 6f 70 65 | 72 61 74 69 6e 67 20 73 |x or ope|rating s|
|00003230| 79 73 74 65 6d 20 73 65 | 72 76 69 63 65 73 20 77 |ystem se|rvices w|
|00003240| 68 69 63 68 20 6d 61 79 | 20 62 65 20 63 61 6c 6c |hich may| be call|
|00003250| 65 64 20 66 72 6f 6d 20 | 61 6e 20 69 6e 74 65 72 |ed from |an inter|
|00003260| 72 75 70 74 20 73 65 72 | 76 69 63 65 20 72 6f 75 |rupt ser|vice rou|
|00003270| 74 69 6e 65 20 6d 61 79 | 20 62 65 20 63 61 6c 6c |tine may| be call|
|00003280| 65 64 20 62 79 20 70 72 | 65 65 6d 70 74 69 76 65 |ed by pr|eemptive|
|00003290| 20 74 68 72 65 61 64 73 | 2e 20 54 68 65 20 54 6f | threads|. The To|
|000032a0| 6f 6c 62 6f 78 20 61 6e | 64 20 4f 53 20 63 61 6c |olbox an|d OS cal|
|000032b0| 6c 69 6e 67 20 72 65 73 | 74 72 69 63 74 69 6f 6e |ling res|triction|
|000032c0| 73 20 69 6e 63 6c 75 64 | 65 20 74 72 61 70 73 20 |s includ|e traps |
|000032d0| 6c 69 6b 65 20 4c 6f 61 | 64 53 65 67 20 77 68 69 |like Loa|dSeg whi|
|000032e0| 63 68 20 67 65 74 20 63 | 61 6c 6c 65 64 20 6f 6e |ch get c|alled on|
|000032f0| 20 62 65 68 61 6c 66 20 | 6f 66 20 79 6f 75 72 20 | behalf |of your |
|00003300| 61 70 70 6c 69 63 61 74 | 69 6f 6e 20 77 68 65 6e |applicat|ion when|
|00003310| 20 61 6e 20 75 6e 6c 6f | 61 64 65 64 20 63 6f 64 | an unlo|aded cod|
|00003320| 65 20 73 65 67 6d 65 6e | 74 20 6e 65 65 64 73 20 |e segmen|t needs |
|00003330| 74 6f 20 62 65 20 6c 6f | 61 64 65 64 2e 20 49 6d |to be lo|aded. Im|
|00003340| 70 6f 72 74 61 6e 74 3a | 20 42 65 20 73 75 72 65 |portant:| Be sure|
|00003350| 20 74 6f 20 70 72 65 6c | 6f 61 64 20 61 6c 6c 20 | to prel|oad all |
|00003360| 63 6f 64 65 20 73 65 67 | 6d 65 6e 74 73 20 74 68 |code seg|ments th|
|00003370| 61 74 20 67 65 74 20 75 | 73 65 64 20 62 79 20 70 |at get u|sed by p|
|00003380| 72 65 65 6d 70 74 69 76 | 65 20 74 68 72 65 61 64 |reemptiv|e thread|
|00003390| 73 2e 20 41 6c 73 6f 20 | 6e 6f 74 65 20 74 68 61 |s. Also |note tha|
|000033a0| 74 20 70 72 65 65 6d 70 | 74 69 76 65 20 74 68 72 |t preemp|tive thr|
|000033b0| 65 61 64 73 2c 20 6c 69 | 6b 65 20 69 6e 74 65 72 |eads, li|ke inter|
|000033c0| 72 75 70 74 20 73 65 72 | 76 69 63 65 20 72 6f 75 |rupt ser|vice rou|
|000033d0| 74 69 6e 65 73 2c 20 6d | 61 79 20 6e 6f 74 20 6d |tines, m|ay not m|
|000033e0| 61 6b 65 20 73 79 6e 63 | 68 72 6f 6e 6f 75 73 20 |ake sync|hronous |
|000033f0| 49 2f 4f 20 72 65 71 75 | 65 73 74 73 2e 0d 09 4d |I/O requ|ests...M|
|00003400| 61 69 6e 20 41 70 70 6c | 69 63 61 74 69 6f 6e 20 |ain Appl|ication |
|00003410| 54 68 72 65 61 64 3a 20 | 54 68 65 20 6d 61 69 6e |Thread: |The main|
|00003420| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 20 74 68 72 | applica|tion thr|
|00003430| 65 61 64 20 69 73 20 61 | 20 63 6f 6f 70 65 72 61 |ead is a| coopera|
|00003440| 74 69 76 65 20 74 68 72 | 65 61 64 20 61 6e 64 20 |tive thr|ead and |
|00003450| 63 6f 6e 74 61 69 6e 73 | 20 74 68 65 20 6d 61 69 |contains| the mai|
|00003460| 6e 20 65 6e 74 72 79 20 | 70 6f 69 6e 74 20 69 6e |n entry |point in|
|00003470| 74 6f 20 74 68 65 20 61 | 70 70 6c 69 63 61 74 69 |to the a|pplicati|
|00003480| 6f 6e 2e 20 54 68 69 73 | 20 74 68 72 65 61 64 20 |on. This| thread |
|00003490| 69 73 20 67 75 61 72 61 | 6e 74 65 65 64 20 74 6f |is guara|nteed to|
|000034a0| 20 65 78 69 73 74 20 61 | 6e 64 20 63 61 6e 20 6e | exist a|nd can n|
|000034b0| 6f 74 20 62 65 20 64 69 | 73 70 6f 73 65 64 20 6f |ot be di|sposed o|
|000034c0| 66 2e 20 41 6c 6c 20 61 | 70 70 6c 69 63 61 74 69 |f. All a|pplicati|
|000034d0| 6f 6e 73 20 77 69 6c 6c | 20 68 61 76 65 20 6f 6e |ons will| have on|
|000034e0| 65 20 6d 61 69 6e 20 61 | 70 70 6c 69 63 61 74 69 |e main a|pplicati|
|000034f0| 6f 6e 20 74 68 72 65 61 | 64 2c 20 65 76 65 6e 20 |on threa|d, even |
|00003500| 69 66 20 74 68 65 79 20 | 61 72 65 20 6e 6f 74 20 |if they |are not |
|00003510| 61 77 61 72 65 20 6f 66 | 20 74 68 65 20 54 68 72 |aware of| the Thr|
|00003520| 65 61 64 20 4d 61 6e 61 | 67 65 72 2e 20 54 68 65 |ead Mana|ger. The|
|00003530| 20 6d 61 69 6e 20 61 70 | 70 6c 69 63 61 74 69 6f | main ap|plicatio|
|00003540| 6e 20 74 68 72 65 61 64 | 20 69 73 20 64 65 66 69 |n thread| is defi|
|00003550| 6e 65 64 20 74 6f 20 62 | 65 20 72 65 73 70 6f 6e |ned to b|e respon|
|00003560| 73 69 62 6c 65 20 66 6f | 72 20 65 76 65 6e 74 20 |sible fo|r event |
|00003570| 67 61 74 68 65 72 69 6e | 67 20 28 76 69 61 20 57 |gatherin|g (via W|
|00003580| 61 69 74 4e 65 78 74 45 | 76 65 6e 74 20 6f 72 20 |aitNextE|vent or |
|00003590| 47 65 74 4e 65 78 74 45 | 76 65 6e 74 29 2e 20 49 |GetNextE|vent). I|
|000035a0| 66 20 65 76 65 6e 74 73 | 20 61 72 65 20 70 65 6e |f events| are pen|
|000035b0| 64 69 6e 67 20 69 6e 20 | 74 68 65 20 61 70 70 6c |ding in |the appl|
|000035c0| 69 63 61 74 69 6f 6e 20 | 65 76 65 6e 74 20 71 75 |ication |event qu|
|000035d0| 65 75 65 20 77 68 65 6e | 20 61 20 67 65 6e 65 72 |eue when| a gener|
|000035e0| 69 63 20 79 69 65 6c 64 | 20 63 61 6c 6c 20 69 73 |ic yield| call is|
|000035f0| 20 6d 61 64 65 20 28 6e | 6f 20 74 68 72 65 61 64 | made (n|o thread|
|00003600| 20 49 44 20 69 73 20 73 | 70 65 63 69 66 69 65 64 | ID is s|pecified|
|00003610| 29 20 62 79 20 61 6e 6f | 74 68 65 72 20 63 6f 6f |) by ano|ther coo|
|00003620| 70 65 72 61 74 69 76 65 | 20 74 68 72 65 61 64 2c |perative| thread,|
|00003630| 20 74 68 65 20 54 68 72 | 65 61 64 20 4d 61 6e 61 | the Thr|ead Mana|
|00003640| 67 65 72 20 73 63 68 65 | 64 75 6c 65 72 20 63 68 |ger sche|duler ch|
|00003650| 6f 6f 73 65 73 20 74 68 | 65 20 6d 61 69 6e 20 61 |ooses th|e main a|
|00003660| 70 70 6c 69 63 61 74 69 | 6f 6e 20 74 68 72 65 61 |pplicati|on threa|
|00003670| 64 20 61 73 20 74 68 65 | 20 6e 65 78 74 20 63 6f |d as the| next co|
|00003680| 6f 70 65 72 61 74 69 76 | 65 20 74 68 72 65 61 64 |operativ|e thread|
|00003690| 20 74 6f 20 72 75 6e 2e | 20 54 68 69 73 20 67 69 | to run.| This gi|
|000036a0| 76 65 73 20 74 68 65 20 | 6d 61 69 6e 20 61 70 70 |ves the |main app|
|000036b0| 6c 69 63 61 74 69 6f 6e | 20 74 68 72 65 61 64 20 |lication| thread |
|000036c0| 61 20 63 68 61 6e 63 65 | 20 74 6f 20 68 61 6e 64 |a chance| to hand|
|000036d0| 6c 65 20 65 76 65 6e 74 | 73 20 66 6f 72 20 75 73 |le event|s for us|
|000036e0| 65 72 20 72 65 73 70 6f | 6e 73 69 76 65 6e 65 73 |er respo|nsivenes|
|000036f0| 73 2e 0d 09 4d 65 6d 6f | 72 79 20 4d 61 6e 61 67 |s...Memo|ry Manag|
|00003700| 65 6d 65 6e 74 3a 20 54 | 68 65 20 54 68 72 65 61 |ement: T|he Threa|
|00003710| 64 20 4d 61 6e 61 67 65 | 72 20 70 72 6f 76 69 64 |d Manage|r provid|
|00003720| 65 73 20 61 20 6d 65 74 | 68 6f 64 20 6f 66 20 63 |es a met|hod of c|
|00003730| 72 65 61 74 69 6e 67 20 | 61 20 70 6f 6f 6c 20 6f |reating |a pool o|
|00003740| 66 20 74 68 72 65 61 64 | 73 2e 20 54 68 69 73 20 |f thread|s. This |
|00003750| 61 6c 6c 6f 77 73 20 74 | 68 65 20 61 70 70 6c 69 |allows t|he appli|
|00003760| 63 61 74 69 6f 6e 20 74 | 6f 20 63 72 65 61 74 65 |cation t|o create|
|00003770| 20 61 20 74 68 72 65 61 | 64 20 70 6f 6f 6c 20 65 | a threa|d pool e|
|00003780| 61 72 6c 79 20 69 6e 20 | 69 74 73 20 65 78 65 63 |arly in |its exec|
|00003790| 75 74 69 6f 6e 20 62 65 | 66 6f 72 65 20 6d 65 6d |ution be|fore mem|
|000037a0| 6f 72 79 20 68 61 73 20 | 62 65 65 6e 20 75 73 65 |ory has |been use|
|000037b0| 64 20 6f 72 20 6f 76 65 | 72 6c 79 20 66 72 61 67 |d or ove|rly frag|
|000037c0| 6d 65 6e 74 65 64 2e 20 | 54 68 72 65 61 64 73 20 |mented. |Threads |
|000037d0| 6d 61 79 20 62 65 20 72 | 65 6d 6f 76 65 64 20 66 |may be r|emoved f|
|000037e0| 72 6f 6d 20 74 68 65 20 | 74 68 72 65 61 64 20 70 |rom the |thread p|
|000037f0| 6f 6f 6c 20 6f 6e 20 61 | 20 73 74 61 63 6b 20 73 |ool on a| stack s|
|00003800| 69 7a 65 20 62 65 73 74 | 20 66 69 74 20 6f 72 20 |ize best| fit or |
|00003810| 65 78 61 63 74 20 6d 61 | 74 63 68 20 62 61 73 69 |exact ma|tch basi|
|00003820| 73 20 66 6f 72 20 62 65 | 74 74 65 72 20 74 68 72 |s for be|tter thr|
|00003830| 65 61 64 20 70 6f 6f 6c | 20 6d 61 6e 61 67 65 6d |ead pool| managem|
|00003840| 65 6e 74 2e 20 54 68 72 | 65 61 64 20 64 61 74 61 |ent. Thr|ead data|
|00003850| 20 73 74 72 75 63 74 75 | 72 65 73 20 63 61 6e 20 | structu|res can |
|00003860| 62 65 20 61 6c 6c 6f 63 | 61 74 65 64 20 61 74 20 |be alloc|ated at |
|00003870| 6d 6f 73 74 20 61 6e 79 | 20 74 69 6d 65 2c 20 70 |most any| time, p|
|00003880| 72 6f 76 69 64 65 64 20 | 74 68 65 20 4d 65 6d 6f |rovided |the Memo|
|00003890| 72 79 20 4d 61 6e 61 67 | 65 72 20 72 6f 75 74 69 |ry Manag|er routi|
|000038a0| 6e 65 20 4d 61 78 41 70 | 70 6c 5a 6f 6e 65 20 68 |ne MaxAp|plZone h|
|000038b0| 61 73 20 62 65 65 6e 20 | 63 61 6c 6c 65 64 20 28 |as been |called (|
|000038c0| 73 65 65 20 74 68 65 20 | 43 6f 6e 73 74 72 61 69 |see the |Constrai|
|000038d0| 6e 74 73 2c 20 47 6f 74 | 63 68 61 73 20 26 20 42 |nts, Got|chas & B|
|000038e0| 75 67 73 20 73 65 63 74 | 69 6f 6e 20 66 6f 72 20 |ugs sect|ion for |
|000038f0| 6d 6f 72 65 20 69 6e 66 | 6f 72 6d 61 74 69 6f 6e |more inf|ormation|
|00003900| 29 2e 20 49 6d 70 6f 72 | 74 61 6e 74 3a 20 49 74 |). Impor|tant: It|
|00003910| 20 69 73 20 63 6f 6e 73 | 69 64 65 72 65 64 20 61 | is cons|idered a|
|00003920| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 20 65 72 72 | program|ming err|
|00003930| 6f 72 20 74 6f 20 61 6c | 6c 6f 63 61 74 65 20 6d |or to al|locate m|
|00003940| 65 6d 6f 72 79 2c 20 6f | 72 20 63 61 75 73 65 20 |emory, o|r cause |
|00003950| 6d 65 6d 6f 72 79 20 74 | 6f 20 62 65 20 61 6c 6c |memory t|o be all|
|00003960| 6f 63 61 74 65 64 2c 20 | 64 75 72 69 6e 67 20 70 |ocated, |during p|
|00003970| 72 65 65 6d 70 74 69 76 | 65 20 65 78 65 63 75 74 |reemptiv|e execut|
|00003980| 69 6f 6e 20 74 69 6d 65 | 20 6f 72 20 66 72 6f 6d |ion time| or from|
|00003990| 20 61 6e 79 20 74 68 72 | 65 61 64 20 6f 74 68 65 | any thr|ead othe|
|000039a0| 72 20 74 68 61 6e 20 74 | 68 65 20 6d 61 69 6e 20 |r than t|he main |
|000039b0| 61 70 70 6c 69 63 61 74 | 69 6f 6e 20 74 68 72 65 |applicat|ion thre|
|000039c0| 61 64 20 62 65 66 6f 72 | 65 20 4d 61 78 41 70 70 |ad befor|e MaxApp|
|000039d0| 6c 5a 6f 6e 65 20 68 61 | 73 20 62 65 65 6e 20 63 |lZone ha|s been c|
|000039e0| 61 6c 6c 65 64 2e 0d 09 | 0d 09 54 68 72 65 61 64 |alled...|..Thread|
|000039f0| 20 73 74 61 63 6b 20 72 | 65 71 75 69 72 65 6d 65 | stack r|equireme|
|00003a00| 6e 74 73 20 61 72 65 20 | 64 65 74 65 72 6d 69 6e |nts are |determin|
|00003a10| 65 64 20 62 79 20 74 68 | 65 20 74 79 70 65 20 6f |ed by th|e type o|
|00003a20| 66 20 74 68 72 65 61 64 | 20 62 65 69 6e 67 20 63 |f thread| being c|
|00003a30| 72 65 61 74 65 64 20 61 | 6e 64 20 74 68 65 20 61 |reated a|nd the a|
|00003a40| 70 70 6c 69 63 61 74 69 | 6f 6e d5 73 20 73 70 65 |pplicati|on.s spe|
|00003a50| 63 69 66 69 63 20 75 73 | 65 20 6f 66 20 74 68 61 |cific us|e of tha|
|00003a60| 74 20 74 68 72 65 61 64 | 2e 20 54 68 65 20 73 74 |t thread|. The st|
|00003a70| 61 63 6b 20 73 69 7a 65 | 20 6f 66 20 61 20 74 68 |ack size| of a th|
|00003a80| 72 65 61 64 20 69 73 20 | 65 6e 74 69 72 65 6c 79 |read is |entirely|
|00003a90| 20 75 70 20 74 6f 20 74 | 68 65 20 64 65 76 65 6c | up to t|he devel|
|00003aa0| 6f 70 65 72 20 2d 20 74 | 68 65 20 54 68 72 65 61 |oper - t|he Threa|
|00003ab0| 64 20 4d 61 6e 61 67 65 | 72 20 63 61 6e 20 6f 6e |d Manage|r can on|
|00003ac0| 6c 79 20 6c 65 74 20 74 | 68 65 20 64 65 76 65 6c |ly let t|he devel|
|00003ad0| 6f 70 65 72 20 6b 6e 6f | 77 20 74 68 65 20 64 65 |oper kno|w the de|
|00003ae0| 66 61 75 6c 74 20 73 69 | 7a 65 20 61 6e 64 20 74 |fault si|ze and t|
|00003af0| 68 65 20 63 75 72 72 65 | 6e 74 6c 79 20 61 76 61 |he curre|ntly ava|
|00003b00| 69 6c 61 62 6c 65 20 74 | 68 72 65 61 64 20 73 74 |ilable t|hread st|
|00003b10| 61 63 6b 20 73 70 61 63 | 65 2e 20 43 6f 6f 70 65 |ack spac|e. Coope|
|00003b20| 72 61 74 69 76 65 20 74 | 68 72 65 61 64 73 20 6d |rative t|hreads m|
|00003b30| 61 79 20 6d 61 6b 65 20 | 54 6f 6f 6c 62 6f 78 20 |ay make |Toolbox |
|00003b40| 61 6e 64 20 4f 53 20 63 | 61 6c 6c 73 20 77 68 69 |and OS c|alls whi|
|00003b50| 63 68 20 72 65 71 75 69 | 72 65 20 61 20 6c 61 72 |ch requi|re a lar|
|00003b60| 67 65 72 20 73 74 61 63 | 6b 20 74 68 61 6e 20 74 |ger stac|k than t|
|00003b70| 68 72 65 61 64 73 20 77 | 68 69 63 68 20 63 61 6e |hreads w|hich can|
|00003b80| 20 6e 6f 74 20 6d 61 6b | 65 20 73 75 63 68 20 63 | not mak|e such c|
|00003b90| 61 6c 6c 73 2e 20 53 74 | 61 63 6b 20 62 61 73 65 |alls. St|ack base|
|00003ba0| 64 20 70 61 72 61 6d 65 | 74 65 72 20 70 61 73 73 |d parame|ter pass|
|00003bb0| 69 6e 67 20 66 72 6f 6d | 20 61 20 74 68 72 65 61 |ing from| a threa|
|00003bc0| 64 20 69 73 20 66 75 6c | 6c 79 20 73 75 70 70 6f |d is ful|ly suppo|
|00003bd0| 72 74 65 64 20 73 69 6e | 63 65 20 74 68 65 20 54 |rted sin|ce the T|
|00003be0| 68 72 65 61 64 20 4d 61 | 6e 61 67 65 72 20 64 6f |hread Ma|nager do|
|00003bf0| 65 73 20 6e 6f 74 20 42 | 6c 6f 63 6b 4d 6f 76 65 |es not B|lockMove|
|00003c00| 20 74 68 72 65 61 64 20 | 73 74 61 63 6b 73 20 69 | thread |stacks i|
|00003c10| 6e 20 61 6e 64 20 6f 75 | 74 20 6f 66 20 74 68 65 |n and ou|t of the|
|00003c20| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e d5 73 20 6d | applica|tion.s m|
|00003c30| 61 69 6e 20 73 74 61 63 | 6b 20 61 72 65 61 2e 20 |ain stac|k area. |
|00003c40| 45 61 63 68 20 74 68 72 | 65 61 64 20 68 61 73 20 |Each thr|ead has |
|00003c50| 69 74 73 20 6f 77 6e 20 | 73 74 61 63 6b 20 77 68 |its own |stack wh|
|00003c60| 69 63 68 20 64 6f 65 73 | 20 6e 6f 74 20 6d 6f 76 |ich does| not mov|
|00003c70| 65 20 6f 6e 63 65 20 61 | 6c 6c 6f 63 61 74 65 64 |e once a|llocated|
|00003c80| 2e 20 0d 09 53 63 68 65 | 64 75 6c 69 6e 67 3a 20 |. ..Sche|duling: |
|00003c90| 41 6c 6c 20 73 63 68 65 | 64 75 6c 69 6e 67 20 6f |All sche|duling o|
|00003ca0| 63 63 75 72 73 20 69 6e | 20 74 68 65 20 63 6f 6e |ccurs in| the con|
|00003cb0| 74 65 78 74 20 6f 66 20 | 74 68 65 20 63 75 72 72 |text of |the curr|
|00003cc0| 65 6e 74 6c 79 20 65 78 | 65 63 75 74 69 6e 67 20 |ently ex|ecuting |
|00003cd0| 61 70 70 6c 69 63 61 74 | 69 6f 6e 2e 20 57 68 65 |applicat|ion. Whe|
|00003ce0| 6e 20 74 68 65 20 61 70 | 70 6c 69 63 61 74 69 6f |n the ap|plicatio|
|00003cf0| 6e 20 67 65 74 73 20 74 | 69 6d 65 20 74 6f 20 72 |n gets t|ime to r|
|00003d00| 75 6e 20 76 69 61 20 74 | 68 65 20 50 72 6f 63 65 |un via t|he Proce|
|00003d10| 73 73 20 4d 61 6e 61 67 | 65 72 2c 20 74 68 65 20 |ss Manag|er, the |
|00003d20| 61 70 70 6c 69 63 61 74 | 69 6f 6e d5 73 20 74 68 |applicat|ion.s th|
|00003d30| 72 65 61 64 73 20 67 65 | 74 20 74 69 6d 65 20 76 |reads ge|t time v|
|00003d40| 69 61 20 74 68 65 20 54 | 68 72 65 61 64 20 4d 61 |ia the T|hread Ma|
|00003d50| 6e 61 67 65 72 2e 20 41 | 70 70 6c 69 63 61 74 69 |nager. A|pplicati|
|00003d60| 6f 6e 73 20 77 68 69 63 | 68 20 61 72 65 20 73 6c |ons whic|h are sl|
|00003d70| 65 65 70 69 6e 67 2c 20 | 61 6e 64 20 68 65 6e 63 |eeping, |and henc|
|00003d80| 65 20 61 72 65 20 6e 6f | 74 20 73 63 68 65 64 75 |e are no|t schedu|
|00003d90| 6c 65 64 20 62 79 20 74 | 68 65 20 50 72 6f 63 65 |led by t|he Proce|
|00003da0| 73 73 20 4d 61 6e 61 67 | 65 72 2c 20 64 6f 20 6e |ss Manag|er, do n|
|00003db0| 6f 74 20 67 65 74 20 74 | 68 65 69 72 20 74 68 72 |ot get t|heir thr|
|00003dc0| 65 61 64 73 20 65 78 65 | 63 75 74 65 64 2e 20 54 |eads exe|cuted. T|
|00003dd0| 68 72 65 61 64 73 20 61 | 72 65 20 70 65 72 2d 61 |hreads a|re per-a|
|00003de0| 70 70 6c 69 63 61 74 69 | 6f 6e 3a 20 77 68 65 6e |pplicati|on: when|
|00003df0| 20 74 68 65 20 61 70 70 | 6c 69 63 61 74 69 6f 6e | the app|lication|
|00003e00| 20 67 65 74 73 20 74 69 | 6d 65 2c 20 69 74 73 20 | gets ti|me, its |
|00003e10| 74 68 72 65 61 64 73 20 | 67 65 74 20 74 69 6d 65 |threads |get time|
|00003e20| 2e 20 0d 09 43 6f 6f 70 | 65 72 61 74 69 76 65 20 |. ..Coop|erative |
|00003e30| 61 6e 64 20 70 72 65 65 | 6d 70 74 69 76 65 20 74 |and pree|mptive t|
|00003e40| 68 72 65 61 64 73 20 61 | 72 65 20 6e 6f 74 20 67 |hreads a|re not g|
|00003e50| 69 76 65 6e 20 61 20 70 | 72 69 6f 72 69 74 79 20 |iven a p|riority |
|00003e60| 61 6e 64 20 61 72 65 20 | 73 63 68 65 64 75 6c 65 |and are |schedule|
|00003e70| 64 20 69 6e 20 61 20 72 | 6f 75 6e 64 2d 72 6f 62 |d in a r|ound-rob|
|00003e80| 69 6e 20 66 61 73 68 69 | 6f 6e 20 6f 72 20 61 73 |in fashi|on or as|
|00003e90| 20 64 69 63 74 61 74 65 | 64 20 62 79 20 61 20 d2 | dictate|d by a .|
|00003ea0| 79 69 65 6c 64 20 74 6f | d3 20 63 61 6c 6c 20 6f |yield to|. call o|
|00003eb0| 72 20 61 20 63 75 73 74 | 6f 6d 20 73 63 68 65 64 |r a cust|om sched|
|00003ec0| 75 6c 65 72 2e 20 42 6f | 74 68 20 74 79 70 65 73 |uler. Bo|th types|
|00003ed0| 20 6f 66 20 74 68 72 65 | 61 64 73 20 61 72 65 20 | of thre|ads are |
|00003ee0| 67 75 61 72 61 6e 74 65 | 65 64 20 74 6f 20 62 65 |guarante|ed to be|
|00003ef0| 67 69 6e 20 65 78 65 63 | 75 74 69 6f 6e 20 69 6e |gin exec|ution in|
|00003f00| 20 74 68 65 20 6e 6f 72 | 6d 61 6c 20 6f 70 65 72 | the nor|mal oper|
|00003f10| 61 74 69 6e 67 20 6d 6f | 64 65 20 6f 66 20 74 68 |ating mo|de of th|
|00003f20| 65 20 61 70 70 6c 69 63 | 61 74 69 6f 6e 2e 20 4e |e applic|ation. N|
|00003f30| 6f 72 6d 61 6c 20 6f 70 | 65 72 61 74 69 6e 67 20 |ormal op|erating |
|00003f40| 6d 6f 64 65 20 69 73 20 | 64 65 66 69 6e 65 64 20 |mode is |defined |
|00003f50| 61 73 20 74 68 65 20 61 | 64 64 72 65 73 73 69 6e |as the a|ddressin|
|00003f60| 67 20 61 6e 64 20 43 50 | 55 20 6f 70 65 72 61 74 |g and CP|U operat|
|00003f70| 69 6f 6e 20 6d 6f 64 65 | 73 20 69 6e 74 6f 20 77 |ion mode|s into w|
|00003f80| 68 69 63 68 20 74 68 65 | 20 61 70 70 6c 69 63 61 |hich the| applica|
|00003f90| 74 69 6f 6e 20 77 61 73 | 20 6c 61 75 6e 63 68 65 |tion was| launche|
|00003fa0| 64 2e 20 54 68 65 20 6f | 70 65 72 61 74 69 6e 67 |d. The o|perating|
|00003fb0| 20 6d 6f 64 65 20 77 69 | 6c 6c 20 65 69 74 68 65 | mode wi|ll eithe|
|00003fc0| 72 20 62 65 20 32 34 20 | 6f 72 20 33 32 2d 62 69 |r be 24 |or 32-bi|
|00003fd0| 74 20 4d 4d 55 20 61 64 | 64 72 65 73 73 69 6e 67 |t MMU ad|dressing|
|00003fe0| 20 6d 6f 64 65 2c 20 61 | 6e 64 20 75 73 65 72 20 | mode, a|nd user |
|00003ff0| 6f 72 20 73 75 70 65 72 | 76 69 73 6f 72 20 43 50 |or super|visor CP|
|00004000| 55 20 65 78 65 63 75 74 | 69 6f 6e 20 6d 6f 64 65 |U execut|ion mode|
|00004010| 2e 20 41 74 20 70 72 65 | 65 6d 70 74 69 76 65 20 |. At pre|emptive |
|00004020| 72 65 73 63 68 65 64 75 | 6c 65 20 74 69 6d 65 2c |reschedu|le time,|
|00004030| 20 74 68 65 20 61 64 64 | 72 65 73 73 69 6e 67 20 | the add|ressing |
|00004040| 6d 6f 64 65 20 6f 66 20 | 74 68 65 20 74 68 72 65 |mode of |the thre|
|00004050| 61 64 20 69 73 20 72 65 | 73 74 6f 72 65 64 20 74 |ad is re|stored t|
|00004060| 6f 20 69 74 73 20 70 72 | 65 65 6d 70 74 65 64 20 |o its pr|eempted |
|00004070| 73 74 61 74 65 2e 20 54 | 68 65 20 43 50 55 20 6f |state. T|he CPU o|
|00004080| 70 65 72 61 74 69 6e 67 | 20 6d 6f 64 65 20 69 73 |perating| mode is|
|00004090| 20 6e 6f 74 20 63 68 61 | 6e 67 65 64 3b 20 72 65 | not cha|nged; re|
|000040a0| 73 63 68 65 64 75 6c 69 | 6e 67 20 77 69 6c 6c 20 |scheduli|ng will |
|000040b0| 6f 6e 6c 79 20 74 61 6b | 65 20 70 6c 61 63 65 20 |only tak|e place |
|000040c0| 69 66 20 74 68 65 20 63 | 75 72 72 65 6e 74 20 74 |if the c|urrent t|
|000040d0| 68 72 65 61 64 20 69 73 | 20 65 78 65 63 75 74 69 |hread is| executi|
|000040e0| 6e 67 20 69 6e 20 74 68 | 65 20 6e 6f 72 6d 61 6c |ng in th|e normal|
|000040f0| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 20 43 50 55 | applica|tion CPU|
|00004100| 20 6f 70 65 72 61 74 69 | 6e 67 20 6d 6f 64 65 2e | operati|ng mode.|
|00004110| 20 49 66 20 74 68 65 20 | 6e 6f 72 6d 61 6c 20 6f | If the |normal o|
|00004120| 70 65 72 61 74 69 6e 67 | 20 6d 6f 64 65 20 6f 66 |perating| mode of|
|00004130| 20 74 68 65 20 43 50 55 | 20 69 73 20 75 73 65 72 | the CPU| is user|
|00004140| 20 6d 6f 64 65 2c 20 61 | 6e 64 20 74 68 65 20 63 | mode, a|nd the c|
|00004150| 75 72 72 65 6e 74 20 74 | 68 72 65 61 64 20 69 73 |urrent t|hread is|
|00004160| 20 65 78 65 63 75 74 69 | 6e 67 20 69 6e 20 73 75 | executi|ng in su|
|00004170| 70 65 72 76 69 73 6f 72 | 20 6d 6f 64 65 20 77 68 |pervisor| mode wh|
|00004180| 65 6e 20 70 72 65 65 6d | 70 74 69 6f 6e 20 6f 63 |en preem|ption oc|
|00004190| 63 75 72 73 2c 20 74 68 | 65 20 54 68 72 65 61 64 |curs, th|e Thread|
|000041a0| 20 4d 61 6e 61 67 65 72 | 20 64 6f 65 73 20 6e 6f | Manager| does no|
|000041b0| 74 20 72 65 73 63 68 65 | 64 75 6c 65 20 61 6e 64 |t resche|dule and|
|000041c0| 20 77 69 6c 6c 20 72 65 | 74 75 72 6e 20 63 6f 6e | will re|turn con|
|000041d0| 74 72 6f 6c 20 62 61 63 | 6b 20 74 6f 20 74 68 65 |trol bac|k to the|
|000041e0| 20 69 6e 74 65 72 72 75 | 70 74 65 64 20 74 68 72 | interru|pted thr|
|000041f0| 65 61 64 2e 0d 09 43 6f | 6f 70 65 72 61 74 69 76 |ead...Co|operativ|
|00004200| 65 20 74 68 72 65 61 64 | 73 20 67 65 74 20 74 69 |e thread|s get ti|
|00004210| 6d 65 20 77 68 65 6e 20 | 61 6e 20 65 78 70 6c 69 |me when |an expli|
|00004220| 63 69 74 20 79 69 65 6c | 64 20 63 61 6c 6c 20 69 |cit yiel|d call i|
|00004230| 73 20 6d 61 64 65 20 74 | 6f 20 63 61 75 73 65 20 |s made t|o cause |
|00004240| 61 20 63 6f 6e 74 65 78 | 74 20 73 77 69 74 63 68 |a contex|t switch|
|00004250| 2e 20 41 6c 6c 20 74 68 | 65 20 72 75 6c 65 73 20 |. All th|e rules |
|00004260| 74 68 61 74 20 61 70 70 | 6c 79 20 74 6f 20 57 61 |that app|ly to Wa|
|00004270| 69 74 4e 65 78 74 45 76 | 65 6e 74 20 6f 72 20 47 |itNextEv|ent or G|
|00004280| 65 74 4e 65 78 74 45 76 | 65 6e 74 20 68 6f 6c 64 |etNextEv|ent hold|
|00004290| 20 74 72 75 65 20 66 6f | 72 20 79 69 65 6c 64 20 | true fo|r yield |
|000042a0| 63 61 6c 6c 73 20 61 63 | 72 6f 73 73 20 63 6f 6f |calls ac|ross coo|
|000042b0| 70 65 72 61 74 69 76 65 | 20 74 68 72 65 61 64 73 |perative| threads|
|000042c0| 2e 20 46 6f 72 20 65 78 | 61 6d 70 6c 65 2c 20 6e |. For ex|ample, n|
|000042d0| 6f 20 61 73 73 75 6d 70 | 74 69 6f 6e 73 20 63 61 |o assump|tions ca|
|000042e0| 6e 20 62 65 20 6d 61 64 | 65 20 61 62 6f 75 74 20 |n be mad|e about |
|000042f0| 74 68 65 20 70 6c 61 63 | 65 6d 65 6e 74 20 6f 66 |the plac|ement of|
|00004300| 20 75 6e 6c 6f 63 6b 65 | 64 20 68 61 6e 64 6c 65 | unlocke|d handle|
|00004310| 73 2e 0d 09 50 72 65 65 | 6d 70 74 69 76 65 20 74 |s...Pree|mptive t|
|00004320| 68 72 65 61 64 73 20 61 | 72 65 20 6e 6f 74 20 72 |hreads a|re not r|
|00004330| 65 71 75 69 72 65 64 20 | 74 6f 20 6d 61 6b 65 20 |equired |to make |
|00004340| 79 69 65 6c 64 20 63 61 | 6c 6c 73 20 74 6f 20 63 |yield ca|lls to c|
|00004350| 61 75 73 65 20 61 20 63 | 6f 6e 74 65 78 74 20 73 |ause a c|ontext s|
|00004360| 77 69 74 63 68 20 28 61 | 6c 74 68 6f 75 67 68 20 |witch (a|lthough |
|00004370| 74 68 65 79 20 63 65 72 | 74 61 69 6e 6c 79 20 6d |they cer|tainly m|
|00004380| 61 79 29 20 61 6e 64 20 | 73 68 61 72 65 20 35 30 |ay) and |share 50|
|00004390| 25 20 6f 66 20 74 68 65 | 69 72 20 43 50 55 20 74 |% of the|ir CPU t|
|000043a0| 69 6d 65 20 77 69 74 68 | 20 74 68 65 20 63 75 72 |ime with| the cur|
|000043b0| 72 65 6e 74 6c 79 20 65 | 78 65 63 75 74 69 6e 67 |rently e|xecuting|
|000043c0| 20 63 6f 6f 70 65 72 61 | 74 69 76 65 20 74 68 72 | coopera|tive thr|
|000043d0| 65 61 64 2e 20 48 6f 77 | 65 76 65 72 2c 20 63 61 |ead. How|ever, ca|
|000043e0| 6c 6c 69 6e 67 20 79 69 | 65 6c 64 20 66 72 6f 6d |lling yi|eld from|
|000043f0| 20 61 20 70 72 65 65 6d | 70 74 69 76 65 20 74 68 | a preem|ptive th|
|00004400| 72 65 61 64 20 69 73 20 | 64 65 73 69 72 61 62 6c |read is |desirabl|
|00004410| 65 20 69 66 20 74 68 61 | 74 20 74 68 72 65 61 64 |e if tha|t thread|
|00004420| 20 69 73 20 6e 6f 74 20 | 63 75 72 72 65 6e 74 6c | is not |currentl|
|00004430| 79 20 62 75 73 79 2e 0d | 09 57 69 74 68 20 74 68 |y busy..|.With th|
|00004440| 65 20 61 64 76 65 6e 74 | 20 6f 66 20 6d 75 6c 74 |e advent| of mult|
|00004450| 69 70 6c 79 20 74 68 72 | 65 61 64 65 64 20 61 70 |iply thr|eaded ap|
|00004460| 70 6c 69 63 61 74 69 6f | 6e 73 20 63 6f 6d 65 73 |plicatio|ns comes|
|00004470| 20 74 68 65 20 69 73 73 | 75 65 20 6f 66 20 64 61 | the iss|ue of da|
|00004480| 74 61 20 63 6f 68 65 72 | 65 6e 63 79 2e 20 54 68 |ta coher|ency. Th|
|00004490| 69 73 20 69 73 20 61 20 | 70 72 6f 62 6c 65 6d 20 |is is a |problem |
|000044a0| 77 68 65 72 65 20 6f 6e | 65 20 74 68 72 65 61 64 |where on|e thread|
|000044b0| 20 6f 66 20 65 78 65 63 | 75 74 69 6f 6e 20 28 65 | of exec|ution (e|
|000044c0| 69 74 68 65 72 20 63 6f | 6f 70 65 72 61 74 69 76 |ither co|operativ|
|000044d0| 65 20 6f 72 20 70 72 65 | 65 6d 70 74 69 76 65 29 |e or pre|emptive)|
|000044e0| 20 69 73 20 6c 6f 6f 6b | 69 6e 67 20 61 74 20 73 | is look|ing at s|
|000044f0| 68 61 72 65 64 20 64 61 | 74 61 20 77 68 69 6c 65 |hared da|ta while|
|00004500| 20 61 6e 6f 74 68 65 72 | 20 74 68 72 65 61 64 20 | another| thread |
|00004510| 69 73 20 63 68 61 6e 67 | 69 6e 67 20 69 74 2e 20 |is chang|ing it. |
|00004520| 54 68 65 20 54 68 72 65 | 61 64 20 4d 61 6e 61 67 |The Thre|ad Manag|
|00004530| 65 72 20 70 72 6f 76 69 | 64 65 73 20 61 20 73 6f |er provi|des a so|
|00004540| 6c 75 74 69 6f 6e 20 74 | 6f 20 74 68 69 73 20 70 |lution t|o this p|
|00004550| 72 6f 62 6c 65 6d 20 62 | 79 20 70 72 6f 76 69 64 |roblem b|y provid|
|00004560| 69 6e 67 20 74 68 65 20 | 61 70 70 6c 69 63 61 74 |ing the |applicat|
|00004570| 69 6f 6e 20 77 69 74 68 | 20 74 68 65 20 61 62 69 |ion with| the abi|
|00004580| 6c 69 74 79 20 74 6f 20 | 64 65 66 69 6e 65 20 61 |lity to |define a|
|00004590| 20 d2 63 72 69 74 69 63 | 61 6c d3 20 73 65 63 74 | .critic|al. sect|
|000045a0| 69 6f 6e 20 6f 66 20 63 | 6f 64 65 20 77 68 69 63 |ion of c|ode whic|
|000045b0| 68 20 6c 6f 63 6b 73 20 | 6f 75 74 20 70 72 65 65 |h locks |out pree|
|000045c0| 6d 70 74 69 6f 6e 2e 20 | 57 69 74 68 20 70 72 65 |mption. |With pre|
|000045d0| 65 6d 70 74 69 6f 6e 20 | 64 69 73 61 62 6c 65 64 |emption |disabled|
|000045e0| 2c 20 61 20 74 68 72 65 | 61 64 20 6d 61 79 20 6c |, a thre|ad may l|
|000045f0| 6f 6f 6b 20 61 74 20 6f | 72 20 63 68 61 6e 67 65 |ook at o|r change|
|00004600| 20 73 68 61 72 65 64 20 | 6f 72 20 67 6c 6f 62 61 | shared |or globa|
|00004610| 6c 20 64 61 74 61 20 73 | 61 66 65 6c 79 2e 20 54 |l data s|afely. T|
|00004620| 68 65 20 d2 63 72 69 74 | 69 63 61 6c d3 20 63 6f |he .crit|ical. co|
|00004630| 64 65 20 6d 65 63 68 61 | 6e 69 73 6d 20 69 73 20 |de mecha|nism is |
|00004640| 70 72 6f 76 69 64 65 64 | 20 74 68 72 6f 75 67 68 |provided| through|
|00004650| 20 74 68 65 20 75 73 65 | 20 6f 66 20 74 68 65 20 | the use| of the |
|00004660| 54 68 72 65 61 64 42 65 | 67 69 6e 43 72 69 74 69 |ThreadBe|ginCriti|
|00004670| 63 61 6c 20 61 6e 64 20 | 54 68 72 65 61 64 45 6e |cal and |ThreadEn|
|00004680| 64 43 72 69 74 69 63 61 | 6c 20 63 61 6c 6c 73 2e |dCritica|l calls.|
|00004690| 20 54 68 72 65 61 64 42 | 65 67 69 6e 43 72 69 74 | ThreadB|eginCrit|
|000046a0| 69 63 61 6c 20 69 6e 63 | 72 65 6d 65 6e 74 73 20 |ical inc|rements |
|000046b0| 61 20 63 6f 75 6e 74 65 | 72 20 73 65 6d 61 70 68 |a counte|r semaph|
|000046c0| 6f 72 65 20 61 6e 64 20 | 74 65 6c 6c 73 20 74 68 |ore and |tells th|
|000046d0| 65 20 54 68 72 65 61 64 | 20 4d 61 6e 61 67 65 72 |e Thread| Manager|
|000046e0| 20 74 6f 20 6c 6f 63 6b | 20 6f 75 74 20 74 68 65 | to lock| out the|
|000046f0| 20 70 72 65 65 6d 70 74 | 69 6f 6e 20 6d 65 63 68 | preempt|ion mech|
|00004700| 61 6e 69 73 6d 2e 20 54 | 68 72 65 61 64 45 6e 64 |anism. T|hreadEnd|
|00004710| 43 72 69 74 69 63 61 6c | 20 64 6f 65 73 20 6a 75 |Critical| does ju|
|00004720| 73 74 20 74 68 65 20 6f | 70 70 6f 73 69 74 65 20 |st the o|pposite |
|00004730| 2d 20 77 68 65 6e 20 74 | 68 65 20 63 6f 75 6e 74 |- when t|he count|
|00004740| 65 72 20 73 65 6d 61 70 | 68 6f 72 65 20 72 65 61 |er semap|hore rea|
|00004750| 63 68 65 73 20 7a 65 72 | 6f 2c 20 74 68 65 20 70 |ches zer|o, the p|
|00004760| 72 65 65 6d 70 74 69 6f | 6e 20 6d 65 63 68 61 6e |reemptio|n mechan|
|00004770| 69 73 6d 20 69 73 20 72 | 65 20 65 6e 61 62 6c 65 |ism is r|e enable|
|00004780| 64 2e 20 54 68 72 65 61 | 64 42 65 67 69 6e 43 72 |d. Threa|dBeginCr|
|00004790| 69 74 63 61 6c 2f 54 68 | 72 65 61 64 45 6e 64 43 |itcal/Th|readEndC|
|000047a0| 72 69 74 69 63 61 6c 20 | 70 61 69 72 20 70 72 6f |ritical |pair pro|
|000047b0| 76 69 64 65 73 20 64 65 | 76 65 6c 6f 70 65 72 73 |vides de|velopers|
|000047c0| 20 77 69 74 68 20 74 68 | 65 20 62 75 69 6c 64 69 | with th|e buildi|
|000047d0| 6e 67 20 62 6c 6f 63 6b | 73 20 6e 65 65 64 65 64 |ng block|s needed|
|000047e0| 20 66 6f 72 20 64 69 72 | 65 63 74 20 73 65 6d 61 | for dir|ect sema|
|000047f0| 70 68 6f 72 65 20 73 75 | 70 70 6f 72 74 2e 0d 09 |phore su|pport...|
|00004800| 57 72 69 74 69 6e 67 20 | 41 20 43 75 73 74 6f 6d |Writing |A Custom|
|00004810| 20 54 68 72 65 61 64 20 | 53 63 68 65 64 75 6c 65 | Thread |Schedule|
|00004820| 72 20 52 6f 75 74 69 6e | 65 3a 20 50 72 65 65 6d |r Routin|e: Preem|
|00004830| 70 74 69 6f 6e 20 69 73 | 20 64 69 73 61 62 6c 65 |ption is| disable|
|00004840| 64 20 77 68 65 6e 20 74 | 68 65 20 63 75 73 74 6f |d when t|he custo|
|00004850| 6d 20 73 63 68 65 64 75 | 6c 65 72 20 69 73 20 63 |m schedu|ler is c|
|00004860| 61 6c 6c 65 64 20 77 68 | 69 63 68 20 70 72 65 76 |alled wh|ich prev|
|00004870| 65 6e 74 73 2c 20 61 6d | 6f 6e 67 20 6f 74 68 65 |ents, am|ong othe|
|00004880| 72 20 74 68 69 6e 67 73 | 2c 20 72 65 65 6e 74 72 |r things|, reentr|
|00004890| 61 6e 63 79 20 70 72 6f | 62 6c 65 6d 73 2e 20 54 |ancy pro|blems. T|
|000048a0| 68 65 72 65 20 73 68 6f | 75 6c 64 20 62 65 20 6e |here sho|uld be n|
|000048b0| 6f 20 79 69 65 6c 64 20 | 6f 72 20 6f 74 68 65 72 |o yield |or other|
|000048c0| 20 73 63 68 65 64 75 6c | 69 6e 67 20 63 61 6c 6c | schedul|ing call|
|000048d0| 73 20 6d 61 64 65 20 61 | 74 20 74 68 69 73 20 74 |s made a|t this t|
|000048e0| 69 6d 65 2e 20 54 68 65 | 20 63 75 73 74 6f 6d 20 |ime. The| custom |
|000048f0| 73 63 68 65 64 75 6c 65 | 72 20 69 73 20 70 72 6f |schedule|r is pro|
|00004900| 76 69 64 65 64 20 77 69 | 74 68 20 61 20 64 61 74 |vided wi|th a dat|
|00004910| 61 20 72 65 63 6f 72 64 | 20 64 65 66 69 6e 69 6e |a record| definin|
|00004920| 67 20 74 68 72 65 61 64 | 20 49 44 20 69 6e 66 6f |g thread| ID info|
|00004930| 72 6d 61 74 69 6f 6e 20 | 77 68 69 63 68 20 69 6e |rmation |which in|
|00004940| 63 6c 75 64 65 73 20 74 | 68 65 20 73 69 7a 65 20 |cludes t|he size |
|00004950| 6f 66 20 74 68 65 20 64 | 61 74 61 20 72 65 63 6f |of the d|ata reco|
|00004960| 72 64 20 28 66 6f 72 20 | 69 6d 70 6f 72 74 61 6e |rd (for |importan|
|00004970| 74 20 66 75 74 75 72 65 | 20 64 69 72 65 63 74 69 |t future| directi|
|00004980| 6f 6e 73 29 2c 20 74 68 | 65 20 63 75 72 72 65 6e |ons), th|e curren|
|00004990| 74 20 74 68 72 65 61 64 | 20 49 44 2c 20 74 68 65 |t thread| ID, the|
|000049a0| 20 73 75 67 67 65 73 74 | 65 64 20 74 68 72 65 61 | suggest|ed threa|
|000049b0| 64 20 49 44 20 28 77 68 | 69 63 68 20 6d 61 79 20 |d ID (wh|ich may |
|000049c0| 62 65 20 6b 4e 6f 54 68 | 72 65 61 64 49 44 29 2c |be kNoTh|readID),|
|000049d0| 20 61 6e 64 20 74 68 65 | 20 63 75 72 72 65 6e 74 | and the| current|
|000049e0| 6c 79 20 69 6e 74 65 72 | 72 75 70 74 65 64 20 63 |ly inter|rupted c|
|000049f0| 6f 6f 70 65 72 61 74 69 | 76 65 20 74 68 72 65 61 |ooperati|ve threa|
|00004a00| 64 20 28 6f 72 20 6b 4e | 6f 54 68 72 65 61 64 49 |d (or kN|oThreadI|
|00004a10| 44 29 2e 20 49 6e 20 61 | 64 64 69 74 69 6f 6e 20 |D). In a|ddition |
|00004a20| 74 6f 20 74 68 69 73 20 | 69 6e 66 6f 72 6d 61 74 |to this |informat|
|00004a30| 69 6f 6e 20 74 68 65 20 | 63 75 73 74 6f 6d 20 73 |ion the |custom s|
|00004a40| 63 68 65 64 75 6c 65 72 | 20 6d 75 73 74 20 68 61 |cheduler| must ha|
|00004a50| 76 65 20 6b 6e 6f 77 6c | 65 64 67 65 20 61 62 6f |ve knowl|edge abo|
|00004a60| 75 74 20 74 68 65 20 74 | 68 72 65 61 64 73 20 69 |ut the t|hreads i|
|00004a70| 74 20 77 69 73 68 65 73 | 20 74 6f 20 73 63 68 65 |t wishes| to sche|
|00004a80| 64 75 6c 65 2e 20 49 66 | 20 74 68 65 20 63 75 73 |dule. If| the cus|
|00004a90| 74 6f 6d 20 73 63 68 65 | 64 75 6c 65 72 20 64 6f |tom sche|duler do|
|00004aa0| 65 73 20 6e 6f 74 20 77 | 69 73 68 20 74 6f 20 73 |es not w|ish to s|
|00004ab0| 65 6c 65 63 74 20 61 20 | 74 68 72 65 61 64 20 69 |elect a |thread i|
|00004ac0| 74 20 63 61 6e 20 70 61 | 73 73 20 62 61 63 6b 20 |t can pa|ss back |
|00004ad0| 74 68 65 20 73 75 67 67 | 65 73 74 65 64 20 74 68 |the sugg|ested th|
|00004ae0| 72 65 61 64 20 49 44 20 | 28 6f 72 20 6b 4e 6f 54 |read ID |(or kNoT|
|00004af0| 68 72 65 61 64 49 44 29 | 20 61 73 20 74 68 65 20 |hreadID)| as the |
|00004b00| 74 68 72 65 61 64 20 74 | 6f 20 73 63 68 65 64 75 |thread t|o schedu|
|00004b10| 6c 65 20 61 6e 64 20 6c | 65 74 20 74 68 65 20 54 |le and l|et the T|
|00004b20| 68 72 65 61 64 20 4d 61 | 6e 61 67 65 72 27 73 20 |hread Ma|nager's |
|00004b30| 64 65 66 61 75 6c 74 20 | 73 63 68 65 64 75 6c 65 |default |schedule|
|00004b40| 72 20 64 65 63 69 64 65 | 2e 20 49 66 20 74 68 65 |r decide|. If the|
|00004b50| 20 63 75 73 74 6f 6d 20 | 73 63 68 65 64 75 6c 65 | custom |schedule|
|00004b60| 72 20 64 6f 65 73 20 6e | 6f 74 20 6b 6e 6f 77 20 |r does n|ot know |
|00004b70| 61 62 6f 75 74 20 61 6c | 6c 20 6f 66 20 74 68 65 |about al|l of the|
|00004b80| 20 74 68 72 65 61 64 73 | 20 62 65 6c 6f 6e 67 69 | threads| belongi|
|00004b90| 6e 67 20 74 6f 20 74 68 | 65 20 61 70 70 6c 69 63 |ng to th|e applic|
|00004ba0| 61 74 69 6f 6e 20 28 69 | 74 20 6d 61 79 20 6e 6f |ation (i|t may no|
|00004bb0| 74 20 69 66 20 74 68 65 | 20 73 79 73 74 65 6d 20 |t if the| system |
|00004bc0| 63 72 65 61 74 65 73 20 | 74 68 72 65 61 64 73 20 |creates |threads |
|00004bd0| 6f 6e 20 62 65 68 61 6c | 66 20 6f 66 20 74 68 65 |on behal|f of the|
|00004be0| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 29 2c 20 69 | applica|tion), i|
|00004bf0| 74 20 73 68 6f 75 6c 64 | 20 6f 63 63 61 73 69 6f |t should| occasio|
|00004c00| 6e 61 6c 6c 79 20 73 65 | 6e 64 20 62 61 63 6b 20 |nally se|nd back |
|00004c10| 74 68 65 20 73 75 67 67 | 65 73 74 65 64 20 74 68 |the sugg|ested th|
|00004c20| 72 65 61 64 20 49 44 20 | 28 6f 72 20 6b 4e 6f 54 |read ID |(or kNoT|
|00004c30| 68 72 65 61 64 49 44 29 | 20 74 6f 20 67 69 76 65 |hreadID)| to give|
|00004c40| 20 6f 74 68 65 72 20 74 | 68 72 65 61 64 73 20 61 | other t|hreads a|
|00004c50| 20 63 68 61 6e 63 65 20 | 74 6f 20 62 65 20 73 63 | chance |to be sc|
|00004c60| 68 65 64 75 6c 65 64 2e | 20 4e 6f 74 65 20 74 68 |heduled.| Note th|
|00004c70| 61 74 20 64 75 65 20 74 | 6f 20 74 68 65 20 72 6f |at due t|o the ro|
|00004c80| 75 6e 64 20 72 6f 62 69 | 6e 20 73 63 68 65 64 75 |und robi|n schedu|
|00004c90| 6c 69 6e 67 20 61 70 70 | 72 6f 61 63 68 2c 20 74 |ling app|roach, t|
|00004ca0| 68 65 20 d4 6f 74 68 65 | 72 d5 20 74 68 72 65 61 |he .othe|r. threa|
|00004cb0| 64 73 20 61 72 65 20 6e | 6f 74 20 67 75 61 72 61 |ds are n|ot guara|
|00004cc0| 6e 74 65 65 64 20 74 6f | 20 62 65 20 6e 65 78 74 |nteed to| be next|
|00004cd0| 20 69 6e 20 6c 69 6e 65 | 20 66 6f 72 20 73 63 68 | in line| for sch|
|00004ce0| 65 64 75 6c 69 6e 67 2e | 20 49 66 20 74 68 65 20 |eduling.| If the |
|00004cf0| 69 6e 74 65 72 72 75 70 | 74 65 64 20 63 6f 6f 70 |interrup|ted coop|
|00004d00| 65 72 61 74 69 76 65 20 | 74 68 72 65 61 64 20 49 |erative |thread I|
|00004d10| 44 20 76 61 72 69 61 62 | 6c 65 20 69 73 20 6e 6f |D variab|le is no|
|00004d20| 74 20 d4 6e 69 6c d5 2c | 20 74 68 65 20 63 75 73 |t .nil.,| the cus|
|00004d30| 74 6f 6d 20 73 63 68 65 | 64 75 6c 65 72 20 77 61 |tom sche|duler wa|
|00004d40| 73 20 63 61 6c 6c 65 64 | 20 64 75 72 69 6e 67 20 |s called| during |
|00004d50| 74 68 65 20 65 78 65 63 | 75 74 69 6f 6e 20 6f 66 |the exec|ution of|
|00004d60| 20 61 20 70 72 65 65 6d | 70 74 69 76 65 20 74 68 | a preem|ptive th|
|00004d70| 72 65 61 64 20 61 6e 64 | 20 6d 75 73 74 20 6e 6f |read and| must no|
|00004d80| 74 20 73 63 68 65 64 75 | 6c 65 20 61 20 63 6f 6f |t schedu|le a coo|
|00004d90| 70 65 72 61 74 69 76 65 | 20 74 68 72 65 61 64 20 |perative| thread |
|00004da0| 6f 74 68 65 72 20 74 68 | 61 6e 20 74 68 65 20 69 |other th|an the i|
|00004db0| 6e 74 65 72 72 75 70 74 | 65 64 20 63 6f 6f 70 65 |nterrupt|ed coope|
|00004dc0| 72 61 74 69 76 65 20 74 | 68 72 65 61 64 2e 20 53 |rative t|hread. S|
|00004dd0| 63 68 65 64 75 6c 69 6e | 67 20 61 20 63 6f 6f 70 |chedulin|g a coop|
|00004de0| 65 72 61 74 69 76 65 20 | 74 68 72 65 61 64 20 61 |erative |thread a|
|00004df0| 74 20 74 68 69 73 20 74 | 69 6d 65 20 77 6f 75 6c |t this t|ime woul|
|00004e00| 64 20 65 66 66 65 63 74 | 69 76 65 6c 79 20 62 65 |d effect|ively be|
|00004e10| 20 63 61 75 73 69 6e 67 | 20 63 6f 6f 70 65 72 61 | causing| coopera|
|00004e20| 74 69 76 65 20 74 68 72 | 65 61 64 20 70 72 65 65 |tive thr|ead pree|
|00004e30| 6d 70 74 69 6f 6e 20 77 | 68 69 63 68 20 63 6f 75 |mption w|hich cou|
|00004e40| 6c 64 20 72 65 73 75 6c | 74 20 69 6e 20 61 20 73 |ld resul|t in a s|
|00004e50| 79 73 74 65 6d 20 6d 69 | 73 75 6e 64 65 72 73 74 |ystem mi|sunderst|
|00004e60| 61 6e 64 69 6e 67 20 28 | 63 72 61 73 68 29 2e 20 |anding (|crash). |
|00004e70| 0d 09 49 6d 70 6f 72 74 | 61 6e 74 3a 20 20 53 63 |..Import|ant: Sc|
|00004e80| 68 65 64 75 6c 69 6e 67 | 20 77 69 74 68 20 6e 61 |heduling| with na|
|00004e90| 74 69 76 65 20 74 68 72 | 65 61 64 73 20 69 73 20 |tive thr|eads is |
|00004ea0| 6c 65 73 73 20 63 6f 6d | 70 6c 69 63 61 74 65 64 |less com|plicated|
|00004eb0| 20 62 65 63 61 75 73 65 | 20 74 68 65 72 65 20 61 | because| there a|
|00004ec0| 72 65 20 6e 6f 20 70 72 | 65 65 6d 70 74 69 76 65 |re no pr|eemptive|
|00004ed0| 20 74 68 72 65 61 64 73 | 2e 20 20 4d 65 61 6e 69 | threads|. Meani|
|00004ee0| 6e 67 20 74 68 65 20 6f | 6e 6c 79 20 77 61 79 20 |ng the o|nly way |
|00004ef0| 72 65 73 63 68 65 64 75 | 6c 69 6e 67 20 68 61 70 |reschedu|ling hap|
|00004f00| 70 65 6e 73 20 69 73 20 | 77 68 65 6e 20 61 20 74 |pens is |when a t|
|00004f10| 68 72 65 61 64 20 79 69 | 65 6c 64 73 20 74 6f 20 |hread yi|elds to |
|00004f20| 61 6e 79 20 6f 74 68 65 | 72 20 74 68 72 65 61 64 |any othe|r thread|
|00004f30| 2e 0d 09 43 6f 6e 74 65 | 78 74 3a 20 54 68 65 20 |...Conte|xt: The |
|00004f40| 64 65 66 61 75 6c 74 20 | 63 6f 6e 74 65 78 74 20 |default |context |
|00004f50| 6f 66 20 61 20 74 68 72 | 65 61 64 20 63 6f 6e 73 |of a thr|ead cons|
|00004f60| 69 73 74 73 20 6f 66 20 | 74 68 65 20 43 50 55 20 |ists of |the CPU |
|00004f70| 72 65 67 69 73 74 65 72 | 73 2c 20 74 68 65 20 46 |register|s, the F|
|00004f80| 50 55 20 72 65 67 69 73 | 74 65 72 73 20 69 66 20 |PU regis|ters if |
|00004f90| 61 6e 20 46 50 55 20 69 | 73 20 70 72 65 73 65 6e |an FPU i|s presen|
|00004fa0| 74 2c 20 61 6e 64 20 61 | 20 66 65 77 20 6c 6f 77 |t, and a| few low|
|00004fb0| 6d 65 6d 20 67 6c 6f 62 | 61 6c 73 2e 20 53 70 65 |mem glob|als. Spe|
|00004fc0| 63 69 66 69 63 61 6c 6c | 79 2c 20 74 68 65 20 73 |cificall|y, the s|
|00004fd0| 61 76 65 64 20 64 61 74 | 61 20 69 73 20 61 73 20 |aved dat|a is as |
|00004fe0| 66 6f 6c 6c 6f 77 73 3a | 0d 43 50 55 20 52 65 67 |follows:|.CPU Reg|
|00004ff0| 69 73 74 65 72 73 09 46 | 50 55 20 52 65 67 69 73 |isters.F|PU Regis|
|00005000| 74 65 72 73 09 0d 52 44 | 30 20 2d 20 52 44 37 09 |ters..RD|0 - RD7.|
|00005010| 46 50 43 52 2c 20 46 50 | 53 52 2c 20 46 50 49 41 |FPCR, FP|SR, FPIA|
|00005020| 52 09 0d 52 41 30 20 2d | 20 52 41 37 09 46 50 30 |R..RA0 -| RA7.FP0|
|00005030| 20 2d 20 46 50 37 09 0d | 53 52 20 28 69 6e 63 6c | - FP7..|SR (incl|
|00005040| 2e 20 43 43 52 29 09 46 | 50 55 20 66 72 61 6d 65 |. CCR).F|PU frame|
|00005050| 09 0d 0d 46 6f 72 20 70 | 6f 77 65 72 20 61 70 70 |...For p|ower app|
|00005060| 6c 69 63 61 74 69 6f 6e | 73 2c 20 74 68 65 20 63 |lication|s, the c|
|00005070| 6f 6e 74 65 78 74 20 6c | 6f 6f 6b 73 20 73 6f 6d |ontext l|ooks som|
|00005080| 65 74 68 69 6e 67 20 6c | 69 6b 65 20 74 68 69 73 |ething l|ike this|
|00005090| 3a 0d 43 50 55 20 52 65 | 67 69 73 74 65 72 73 09 |:.CPU Re|gisters.|
|000050a0| 46 50 55 20 52 65 67 69 | 73 74 65 72 73 09 4d 61 |FPU Regi|sters.Ma|
|000050b0| 63 68 69 6e 65 20 52 65 | 67 69 73 74 65 72 73 09 |chine Re|gisters.|
|000050c0| 0d 52 30 2d 52 33 31 09 | 46 50 30 2d 46 50 33 31 |.R0-R31.|FP0-FP31|
|000050d0| 09 43 54 52 2c 20 4c 52 | 2c 20 50 43 09 0d 09 46 |.CTR, LR|, PC...F|
|000050e0| 50 53 43 52 09 43 52 2c | 20 58 45 52 09 0d 0d 09 |PSCR.CR,| XER....|
|000050f0| 54 68 65 20 74 68 72 65 | 61 64 20 63 6f 6e 74 65 |The thre|ad conte|
|00005100| 78 74 20 6c 69 76 65 73 | 20 6f 6e 20 61 20 74 68 |xt lives| on a th|
|00005110| 72 65 61 64 d5 73 20 41 | 37 20 73 74 61 63 6b 20 |read.s A|7 stack |
|00005120| 61 6e 64 20 74 68 65 20 | 6c 6f 63 61 74 69 6f 6e |and the |location|
|00005130| 20 6f 66 20 74 68 65 20 | 74 68 72 65 61 64 20 63 | of the |thread c|
|00005140| 6f 6e 74 65 78 74 20 69 | 73 20 73 61 76 65 64 20 |ontext i|s saved |
|00005150| 61 74 20 63 6f 6e 74 65 | 78 74 20 73 77 69 74 63 |at conte|xt switc|
|00005160| 68 20 74 69 6d 65 2e 20 | 54 68 65 20 41 35 20 72 |h time. |The A5 r|
|00005170| 65 67 69 73 74 65 72 20 | 77 68 69 63 68 20 63 6f |egister |which co|
|00005180| 6e 74 61 69 6e 73 20 61 | 20 70 6f 69 6e 74 65 72 |ntains a| pointer|
|00005190| 20 74 6f 20 74 68 65 20 | 61 70 70 6c 69 63 61 74 | to the |applicat|
|000051a0| 69 6f 6e d5 73 20 d2 41 | 35 20 77 6f 72 6c 64 d3 |ion.s .A|5 world.|
|000051b0| 20 61 6e 64 20 74 68 65 | 20 69 6e 69 74 69 61 6c | and the| initial|
|000051c0| 20 74 68 72 65 61 64 20 | 4d 4d 55 20 6d 6f 64 65 | thread |MMU mode|
|000051d0| 20 69 73 20 69 6e 69 74 | 69 61 6c 6c 79 20 73 65 | is init|ially se|
|000051e0| 74 20 74 68 65 20 73 61 | 6d 65 20 61 73 20 74 68 |t the sa|me as th|
|000051f0| 65 20 6d 61 69 6e 20 61 | 70 70 6c 69 63 61 74 69 |e main a|pplicati|
|00005200| 6f 6e 20 74 68 72 65 61 | 64 2e 20 54 68 69 73 20 |on threa|d. This |
|00005210| 61 6c 6c 6f 77 73 20 61 | 6c 6c 20 74 68 72 65 61 |allows a|ll threa|
|00005220| 64 73 20 74 6f 20 73 68 | 61 72 65 20 69 6e 20 74 |ds to sh|are in t|
|00005230| 68 65 20 75 73 65 20 6f | 66 20 74 68 65 20 61 70 |he use o|f the ap|
|00005240| 70 6c 69 63 61 74 69 6f | 6e d5 73 20 41 35 20 77 |plicatio|n.s A5 w|
|00005250| 6f 72 6c 64 20 77 68 69 | 63 68 20 67 69 76 65 73 |orld whi|ch gives|
|00005260| 20 74 68 72 65 61 64 73 | 20 61 63 63 65 73 73 20 | threads| access |
|00005270| 74 6f 20 6f 70 65 6e 20 | 66 69 6c 65 73 20 61 6e |to open |files an|
|00005280| 64 20 72 65 73 6f 75 72 | 63 65 20 63 68 61 69 6e |d resour|ce chain|
|00005290| 73 2c 20 66 6f 72 20 65 | 78 61 6d 70 6c 65 2e 20 |s, for e|xample. |
|000052a0| 54 68 65 20 4d 4d 55 20 | 6d 6f 64 65 20 6f 66 20 |The MMU |mode of |
|000052b0| 61 20 74 68 72 65 61 64 | 20 69 73 20 73 61 76 65 |a thread| is save|
|000052c0| 64 20 61 77 61 79 2c 20 | 61 6e 64 20 74 68 65 20 |d away, |and the |
|000052d0| 6d 6f 64 65 20 6f 66 20 | 74 68 65 20 69 6e 74 65 |mode of |the inte|
|000052e0| 72 72 75 70 74 65 64 20 | 74 68 72 65 61 64 20 69 |rrupted |thread i|
|000052f0| 73 20 72 65 73 74 6f 72 | 65 64 20 74 6f 20 61 6c |s restor|ed to al|
|00005300| 6c 6f 77 20 70 72 65 65 | 6d 70 74 69 6f 6e 20 6f |low pree|mption o|
|00005310| 66 20 74 68 72 65 61 64 | 73 20 77 68 69 63 68 20 |f thread|s which |
|00005320| 63 68 61 6e 67 65 20 74 | 68 65 20 4d 4d 55 20 6f |change t|he MMU o|
|00005330| 70 65 72 61 74 69 6e 67 | 20 6d 6f 64 65 2e 20 54 |perating| mode. T|
|00005340| 68 65 20 46 50 55 20 63 | 6f 6e 74 65 78 74 20 69 |he FPU c|ontext i|
|00005350| 73 20 66 75 6c 6c 79 20 | 73 61 76 65 64 20 61 6c |s fully |saved al|
|00005360| 6f 6e 67 20 77 69 74 68 | 20 74 68 65 20 63 75 72 |ong with| the cur|
|00005370| 72 65 6e 74 20 46 50 55 | 20 66 72 61 6d 65 2e 20 |rent FPU| frame. |
|00005380| 0d 09 57 72 69 74 69 6e | 67 20 61 20 43 75 73 74 |..Writin|g a Cust|
|00005390| 6f 6d 20 54 68 72 65 61 | 64 20 43 6f 6e 74 65 78 |om Threa|d Contex|
|000053a0| 74 20 53 77 69 74 63 68 | 69 6e 67 20 52 6f 75 74 |t Switch|ing Rout|
|000053b0| 69 6e 65 3a 20 50 72 65 | 65 6d 70 74 69 6f 6e 20 |ine: Pre|emption |
|000053c0| 69 73 20 64 69 73 61 62 | 6c 65 64 20 77 68 65 6e |is disab|led when|
|000053d0| 20 74 68 65 20 63 75 73 | 74 6f 6d 20 73 77 69 74 | the cus|tom swit|
|000053e0| 63 68 69 6e 67 20 72 6f | 75 74 69 6e 65 20 69 73 |ching ro|utine is|
|000053f0| 20 63 61 6c 6c 65 64 20 | 77 68 69 63 68 20 70 72 | called |which pr|
|00005400| 65 76 65 6e 74 73 2c 20 | 61 6d 6f 6e 67 20 6f 74 |events, |among ot|
|00005410| 68 65 72 20 74 68 69 6e | 67 73 2c 20 72 65 65 6e |her thin|gs, reen|
|00005420| 74 72 61 6e 63 79 20 70 | 72 6f 62 6c 65 6d 73 2e |trancy p|roblems.|
|00005430| 20 54 68 65 72 65 20 73 | 68 6f 75 6c 64 20 62 65 | There s|hould be|
|00005440| 20 6e 6f 20 79 69 65 6c | 64 20 6f 72 20 6f 74 68 | no yiel|d or oth|
|00005450| 65 72 20 73 63 68 65 64 | 75 6c 69 6e 67 20 63 61 |er sched|uling ca|
|00005460| 6c 6c 73 20 6d 61 64 65 | 20 61 74 20 74 68 69 73 |lls made| at this|
|00005470| 20 74 69 6d 65 2e 20 57 | 68 65 6e 20 61 20 63 75 | time. W|hen a cu|
|00005480| 73 74 6f 6d 20 63 6f 6e | 74 65 78 74 20 73 77 69 |stom con|text swi|
|00005490| 74 63 68 69 6e 67 20 72 | 6f 75 74 69 6e 65 20 69 |tching r|outine i|
|000054a0| 73 20 63 61 6c 6c 65 64 | 2c 20 20 74 68 72 65 61 |s called|, threa|
|000054b0| 64 20 63 6f 6e 74 65 78 | 74 20 69 73 20 69 6e 20 |d contex|t is in |
|000054c0| 74 72 61 6e 73 69 74 69 | 6f 6e 2c 20 73 6f 20 63 |transiti|on, so c|
|000054d0| 61 6c 6c 73 20 74 6f 20 | 47 65 74 43 75 72 72 65 |alls to |GetCurre|
|000054e0| 6e 74 54 68 72 65 61 64 | 20 61 6e 64 20 75 73 65 |ntThread| and use|
|000054f0| 73 20 6f 66 20 6b 43 75 | 72 72 65 6e 74 54 68 72 |s of kCu|rrentThr|
|00005500| 65 61 64 49 44 20 77 69 | 6c 6c 20 6e 6f 74 20 62 |eadID wi|ll not b|
|00005510| 65 20 61 70 70 72 6f 70 | 72 69 61 74 65 2e 20 43 |e approp|riate. C|
|00005520| 75 73 74 6f 6d 20 73 77 | 69 74 63 68 69 6e 67 20 |ustom sw|itching |
|00005530| 72 6f 75 74 69 6e 65 73 | 20 61 72 65 20 64 65 66 |routines| are def|
|00005540| 69 6e 65 64 20 6f 6e 20 | 61 20 70 65 72 2d 74 68 |ined on |a per-th|
|00005550| 72 65 61 64 20 69 6e 20 | 6f 72 20 6f 75 74 20 62 |read in |or out b|
|00005560| 61 73 69 73 2e 20 45 61 | 63 68 20 74 68 72 65 61 |asis. Ea|ch threa|
|00005570| 64 20 69 73 20 74 72 65 | 61 74 65 64 20 73 65 70 |d is tre|ated sep|
|00005580| 61 72 61 74 65 6c 79 2c | 20 77 68 69 63 68 20 61 |arately,| which a|
|00005590| 6c 6c 6f 77 73 20 74 68 | 72 65 61 64 73 20 74 6f |llows th|reads to|
|000055a0| 20 6d 69 78 20 61 6e 64 | 20 6d 61 74 63 68 20 63 | mix and| match c|
|000055b0| 75 73 74 6f 6d 20 73 77 | 69 74 63 68 65 72 73 20 |ustom sw|itchers |
|000055c0| 61 6e 64 20 70 61 72 61 | 6d 65 74 65 72 73 2e 20 |and para|meters. |
|000055d0| 20 41 20 63 75 73 74 6f | 6d 20 63 6f 6e 74 65 78 | A custo|m contex|
|000055e0| 74 20 73 77 69 74 63 68 | 65 72 20 6d 61 79 20 62 |t switch|er may b|
|000055f0| 65 20 64 65 66 69 6e 65 | 64 20 66 6f 72 20 65 6e |e define|d for en|
|00005600| 74 65 72 69 6e 67 20 61 | 20 74 68 72 65 61 64 20 |tering a| thread |
|00005610| 61 6e 64 20 61 6e 6f 74 | 68 65 72 20 66 6f 72 20 |and anot|her for |
|00005620| 65 78 69 74 69 6e 67 20 | 74 68 65 20 73 61 6d 65 |exiting |the same|
|00005630| 20 74 68 72 65 61 64 2e | 20 20 45 61 63 68 20 63 | thread.| Each c|
|00005640| 6f 6e 74 65 78 74 20 73 | 77 69 74 63 68 69 6e 67 |ontext s|witching|
|00005650| 20 70 72 6f 63 65 64 75 | 72 65 20 69 73 20 70 61 | procedu|re is pa|
|00005660| 73 73 65 64 20 61 20 70 | 61 72 61 6d 65 74 65 72 |ssed a p|arameter|
|00005670| 20 74 6f 20 62 65 20 75 | 73 65 64 20 61 74 20 74 | to be u|sed at t|
|00005680| 68 65 20 61 70 70 6c 69 | 63 61 74 69 6f 6e d5 73 |he appli|cation.s|
|00005690| 20 64 69 73 63 72 65 74 | 69 6f 6e 2e 20 46 6f 72 | discret|ion. For|
|000056a0| 20 65 78 61 6d 70 6c 65 | 2c 20 74 68 65 72 65 20 | example|, there |
|000056b0| 63 6f 75 6c 64 20 62 65 | 20 6f 6e 65 20 63 75 73 |could be| one cus|
|000056c0| 74 6f 6d 20 73 77 69 74 | 63 68 69 6e 67 20 72 6f |tom swit|ching ro|
|000056d0| 75 74 69 6e 65 20 74 68 | 61 74 20 69 73 20 69 6e |utine th|at is in|
|000056e0| 73 74 61 6c 6c 65 64 20 | 77 69 74 68 20 61 20 64 |stalled |with a d|
|000056f0| 69 66 66 65 72 65 6e 74 | 20 70 61 72 61 6d 65 74 |ifferent| paramet|
|00005700| 65 72 20 6f 6e 20 65 61 | 63 68 20 74 68 72 65 61 |er on ea|ch threa|
|00005710| 64 2e 20 0d 4e 6f 74 65 | 3a 20 49 66 20 61 20 63 |d. .Note|: If a c|
|00005720| 75 73 74 6f 6d 20 74 68 | 72 65 61 64 20 73 77 69 |ustom th|read swi|
|00005730| 74 63 68 65 72 2d 69 6e | 6e 65 72 20 69 73 20 69 |tcher-in|ner is i|
|00005740| 6e 73 74 61 6c 6c 65 64 | 2c 20 69 74 20 77 69 6c |nstalled|, it wil|
|00005750| 6c 20 62 65 20 63 61 6c | 6c 65 64 20 62 65 66 6f |l be cal|led befo|
|00005760| 72 65 20 74 68 65 20 74 | 68 72 65 61 64 20 62 65 |re the t|hread be|
|00005770| 67 69 6e 73 20 65 78 65 | 63 75 74 69 6f 6e 20 61 |gins exe|cution a|
|00005780| 74 20 74 68 65 20 74 68 | 72 65 61 64 20 65 6e 74 |t the th|read ent|
|00005790| 72 79 20 70 6f 69 6e 74 | 2e 20 0d 09 49 6d 70 6f |ry point|. ..Impo|
|000057a0| 72 74 61 6e 74 3a 20 20 | 54 68 65 20 65 6e 74 69 |rtant: |The enti|
|000057b0| 72 65 20 63 6f 6e 74 65 | 78 74 20 69 73 20 73 61 |re conte|xt is sa|
|000057c0| 76 65 64 20 62 79 20 54 | 68 72 65 61 64 73 4c 69 |ved by T|hreadsLi|
|000057d0| 62 20 66 6f 72 20 61 6e | 79 20 6e 61 74 69 76 65 |b for an|y native|
|000057e0| 20 61 70 70 6c 69 63 61 | 74 69 6f 6e 2e 20 20 54 | applica|tion. T|
|000057f0| 68 69 73 20 69 73 20 64 | 75 65 20 74 6f 20 74 68 |his is d|ue to th|
|00005800| 65 20 66 61 63 74 20 74 | 68 61 74 20 63 6f 6d 70 |e fact t|hat comp|
|00005810| 69 6c 65 72 73 20 63 61 | 6e 20 75 73 65 20 61 6c |ilers ca|n use al|
|00005820| 6c 20 74 68 65 20 72 65 | 67 69 73 74 65 72 73 20 |l the re|gisters |
|00005830| 64 75 72 69 6e 67 20 6f | 70 74 69 6d 69 7a 61 74 |during o|ptimizat|
|00005840| 69 6f 6e 2c 20 65 76 65 | 6e 20 74 68 65 20 66 6c |ion, eve|n the fl|
|00005850| 6f 61 74 69 6e 67 20 70 | 6f 69 6e 74 20 6f 6e 65 |oating p|oint one|
|00005860| 73 2e 0d 50 72 6f 67 72 | 61 6d 6d 61 74 69 63 20 |s..Progr|ammatic |
|00005870| 49 6e 74 65 72 66 61 63 | 65 0d 44 61 74 61 20 54 |Interfac|e.Data T|
|00005880| 79 70 65 73 0d 54 68 65 | 20 54 68 72 65 61 64 20 |ypes.The| Thread |
|00005890| 47 65 73 74 61 6c 74 20 | 73 65 6c 65 63 74 6f 72 |Gestalt |selector|
|000058a0| 20 61 6e 64 20 62 69 74 | 20 66 69 65 6c 64 20 64 | and bit| field d|
|000058b0| 65 66 69 6e 69 74 69 6f | 6e 20 61 72 65 20 75 73 |efinitio|n are us|
|000058c0| 65 64 20 74 6f 20 64 65 | 74 65 72 6d 69 6e 65 20 |ed to de|termine |
|000058d0| 69 66 20 74 68 65 20 74 | 68 72 65 61 64 73 20 70 |if the t|hreads p|
|000058e0| 61 63 6b 61 67 65 20 69 | 73 20 69 6e 73 74 61 6c |ackage i|s instal|
|000058f0| 6c 65 64 2e 20 54 68 65 | 20 67 65 73 74 61 6c 74 |led. The| gestalt|
|00005900| 54 68 72 65 61 64 73 50 | 72 65 73 65 6e 74 20 62 |ThreadsP|resent b|
|00005910| 69 74 20 69 6e 20 74 68 | 65 20 72 65 73 75 6c 74 |it in th|e result|
|00005920| 20 77 69 6c 6c 20 62 65 | 20 74 72 75 65 20 69 66 | will be| true if|
|00005930| 20 74 68 65 20 54 68 72 | 65 61 64 20 4d 61 6e 61 | the Thr|ead Mana|
|00005940| 67 65 72 20 69 73 20 69 | 6e 73 74 61 6c 6c 65 64 |ger is i|nstalled|
|00005950| 2e 20 4f 74 68 65 72 20 | 62 69 74 73 20 69 6e 20 |. Other |bits in |
|00005960| 74 68 65 20 72 65 73 75 | 6c 74 20 66 69 65 6c 64 |the resu|lt field|
|00005970| 20 61 72 65 20 72 65 73 | 65 72 76 65 64 20 66 6f | are res|erved fo|
|00005980| 72 20 66 75 74 75 72 65 | 20 64 65 66 69 6e 69 74 |r future| definit|
|00005990| 69 6f 6e 2e 0d 43 4f 4e | 53 54 0d 09 67 65 73 74 |ion..CON|ST..gest|
|000059a0| 61 6c 74 54 68 72 65 61 | 64 4d 67 72 41 74 74 72 |altThrea|dMgrAttr|
|000059b0| 09 09 3d 20 d4 74 68 64 | 73 d5 3b 09 7b 54 68 72 |..= .thd|s.;.{Thr|
|000059c0| 65 61 64 20 4d 61 6e 61 | 67 65 72 20 61 74 74 72 |ead Mana|ger attr|
|000059d0| 69 62 75 74 65 73 7d 0d | 09 67 65 73 74 61 6c 74 |ibutes}.|.gestalt|
|000059e0| 54 68 72 65 61 64 4d 67 | 72 50 72 65 73 65 6e 74 |ThreadMg|rPresent|
|000059f0| 09 3d 20 30 3b 09 7b 62 | 69 74 20 74 72 75 65 20 |.= 0;.{b|it true |
|00005a00| 69 66 20 54 68 72 65 61 | 64 73 20 70 72 65 73 65 |if Threa|ds prese|
|00005a10| 6e 74 7d 0d 09 67 65 73 | 74 61 6c 74 53 70 65 63 |nt}..ges|taltSpec|
|00005a20| 69 66 69 63 4d 61 74 63 | 68 53 75 70 70 6f 72 74 |ificMatc|hSupport|
|00005a30| 09 3d 20 31 3b 09 7b 62 | 69 74 20 74 72 75 65 20 |.= 1;.{b|it true |
|00005a40| 69 66 20 d4 65 78 61 63 | 74 20 6d 61 74 63 68 d5 |if .exac|t match.|
|00005a50| 7d 0d 09 09 09 09 09 7b | 41 50 49 20 73 75 70 70 |}......{|API supp|
|00005a60| 6f 72 74 65 64 7d 0d 09 | 67 65 73 74 61 6c 74 54 |orted}..|gestaltT|
|00005a70| 68 72 65 61 64 73 4c 69 | 62 72 61 72 79 50 72 65 |hreadsLi|braryPre|
|00005a80| 73 65 6e 74 20 3d 20 32 | 3b 09 7b 62 69 74 20 74 |sent = 2|;.{bit t|
|00005a90| 72 75 65 20 69 66 20 54 | 68 72 65 61 64 73 4c 69 |rue if T|hreadsLi|
|00005aa0| 62 20 69 73 7d 0d 09 09 | 09 09 09 7b 70 72 65 73 |b is}...|...{pres|
|00005ab0| 65 6e 74 7d 0d 54 68 65 | 20 54 68 72 65 61 64 53 |ent}.The| ThreadS|
|00005ac0| 74 61 74 65 20 64 61 74 | 61 20 74 79 70 65 20 69 |tate dat|a type i|
|00005ad0| 6e 64 69 63 61 74 65 73 | 20 74 68 65 20 67 65 6e |ndicates| the gen|
|00005ae0| 65 72 61 6c 20 6f 70 65 | 72 61 74 69 6f 6e 61 6c |eral ope|rational|
|00005af0| 20 73 74 61 74 75 73 20 | 6f 66 20 61 20 74 68 72 | status |of a thr|
|00005b00| 65 61 64 2e 20 20 41 20 | 74 68 72 65 61 64 20 6d |ead. A |thread m|
|00005b10| 61 79 20 62 65 20 77 61 | 69 74 69 6e 67 20 74 6f |ay be wa|iting to|
|00005b20| 20 65 78 65 63 75 74 65 | 2c 20 73 75 73 70 65 6e | execute|, suspen|
|00005b30| 64 65 64 20 66 72 6f 6d | 20 65 78 65 63 75 74 69 |ded from| executi|
|00005b40| 6f 6e 2c 20 6f 72 20 65 | 78 65 63 75 74 69 6e 67 |on, or e|xecuting|
|00005b50| 2e 0d 54 59 50 45 0d 09 | 54 68 72 65 61 64 53 74 |..TYPE..|ThreadSt|
|00005b60| 61 74 65 09 3d 20 49 4e | 54 45 47 45 52 3b 0d 43 |ate.= IN|TEGER;.C|
|00005b70| 4f 4e 53 54 0d 09 6b 52 | 65 61 64 79 54 68 72 65 |ONST..kR|eadyThre|
|00005b80| 61 64 53 74 61 74 65 09 | 3d 20 30 3b 09 7b 74 68 |adState.|= 0;.{th|
|00005b90| 72 65 61 64 20 69 73 20 | 65 6c 69 67 69 62 6c 65 |read is |eligible|
|00005ba0| 20 74 6f 20 72 75 6e 7d | 0d 09 6b 53 74 6f 70 70 | to run}|..kStopp|
|00005bb0| 65 64 54 68 72 65 61 64 | 53 74 61 74 65 09 3d 20 |edThread|State.= |
|00005bc0| 31 3b 09 7b 74 68 72 65 | 61 64 20 69 73 20 6e 6f |1;.{thre|ad is no|
|00005bd0| 74 20 65 6c 69 67 69 62 | 6c 65 20 74 6f 20 72 75 |t eligib|le to ru|
|00005be0| 6e 7d 0d 09 6b 52 75 6e | 6e 69 6e 67 54 68 72 65 |n}..kRun|ningThre|
|00005bf0| 61 64 53 74 61 74 65 09 | 3d 20 32 3b 09 7b 74 68 |adState.|= 2;.{th|
|00005c00| 72 65 61 64 20 69 73 20 | 72 75 6e 6e 69 6e 67 7d |read is |running}|
|00005c10| 0d 54 68 65 20 54 68 72 | 65 61 64 54 61 73 6b 52 |.The Thr|eadTaskR|
|00005c20| 65 66 20 69 73 20 75 73 | 65 64 20 74 6f 20 61 6c |ef is us|ed to al|
|00005c30| 6c 6f 77 20 63 61 6c 6c | 73 20 74 6f 20 74 68 65 |low call|s to the|
|00005c40| 20 54 68 72 65 61 64 20 | 4d 61 6e 61 67 65 72 20 | Thread |Manager |
|00005c50| 61 74 20 61 20 74 69 6d | 65 20 77 68 65 6e 20 74 |at a tim|e when t|
|00005c60| 68 65 20 61 70 70 6c 69 | 63 61 74 69 6f 6e 20 63 |he appli|cation c|
|00005c70| 6f 6e 74 65 78 74 20 69 | 73 20 6e 6f 74 20 6e 65 |ontext i|s not ne|
|00005c80| 63 65 73 73 61 72 69 6c | 79 20 74 68 65 20 63 75 |cessaril|y the cu|
|00005c90| 72 72 65 6e 74 20 63 6f | 6e 74 65 78 74 2e 0d 54 |rrent co|ntext..T|
|00005ca0| 59 50 45 0d 09 54 68 72 | 65 61 64 54 61 73 6b 52 |YPE..Thr|eadTaskR|
|00005cb0| 65 66 09 3d 20 50 74 72 | 3b 0d 54 68 65 20 54 68 |ef.= Ptr|;.The Th|
|00005cc0| 72 65 61 64 53 74 79 6c | 65 20 64 61 74 61 20 74 |readStyl|e data t|
|00005cd0| 79 70 65 20 69 6e 64 69 | 63 61 74 65 73 20 74 68 |ype indi|cates th|
|00005ce0| 65 20 62 72 6f 61 64 20 | 63 68 61 72 61 63 74 65 |e broad |characte|
|00005cf0| 72 69 73 74 69 63 73 20 | 6f 66 20 61 20 74 68 72 |ristics |of a thr|
|00005d00| 65 61 64 2e 20 20 41 20 | 63 6f 6f 70 65 72 61 74 |ead. A |cooperat|
|00005d10| 69 76 65 20 74 68 72 65 | 61 64 20 69 73 20 6f 6e |ive thre|ad is on|
|00005d20| 65 20 77 68 6f 73 65 20 | 65 78 65 63 75 74 69 6f |e whose |executio|
|00005d30| 6e 20 65 6e 76 69 72 6f | 6e 6d 65 6e 74 20 69 73 |n enviro|nment is|
|00005d40| 20 73 75 66 66 69 63 69 | 65 6e 74 20 66 6f 72 20 | suffici|ent for |
|00005d50| 63 61 6c 6c 69 6e 67 20 | 54 6f 6f 6c 62 6f 78 20 |calling |Toolbox |
|00005d60| 72 6f 75 74 69 6e 65 73 | 20 28 74 68 69 73 20 72 |routines| (this r|
|00005d70| 65 71 75 69 72 65 73 20 | 61 20 6c 61 72 67 65 72 |equires |a larger|
|00005d80| 20 73 74 61 63 6b 2c 20 | 66 6f 72 20 65 78 61 6d | stack, |for exam|
|00005d90| 70 6c 65 29 2e 20 20 41 | 20 70 72 65 65 6d 70 74 |ple). A| preempt|
|00005da0| 69 76 65 20 74 68 72 65 | 61 64 20 69 73 20 6f 6e |ive thre|ad is on|
|00005db0| 65 20 74 68 61 74 20 64 | 6f 65 73 20 6e 6f 74 20 |e that d|oes not |
|00005dc0| 6e 65 65 64 20 74 6f 20 | 65 78 70 6c 69 63 69 74 |need to |explicit|
|00005dd0| 6c 79 20 79 69 65 6c 64 | 20 63 6f 6e 74 72 6f 6c |ly yield| control|
|00005de0| 2c 20 61 6e 64 20 65 78 | 65 63 75 74 65 73 20 70 |, and ex|ecutes p|
|00005df0| 72 65 65 6d 70 74 69 76 | 65 6c 79 20 77 69 74 68 |reemptiv|ely with|
|00005e00| 20 61 6c 6c 20 6f 74 68 | 65 72 20 74 68 72 65 61 | all oth|er threa|
|00005e10| 64 73 2e 0d 54 59 50 45 | 0d 09 54 68 72 65 61 64 |ds..TYPE|..Thread|
|00005e20| 53 74 79 6c 65 09 3d 20 | 4c 4f 4e 47 49 4e 54 3b |Style.= |LONGINT;|
|00005e30| 0d 43 4f 4e 53 54 0d 09 | 6b 43 6f 6f 70 65 72 61 |.CONST..|kCoopera|
|00005e40| 74 69 76 65 54 68 72 65 | 61 64 09 3d 20 31 3b 09 |tiveThre|ad.= 1;.|
|00005e50| 7b 74 68 72 65 61 64 20 | 63 61 6e 20 75 73 65 20 |{thread |can use |
|00005e60| 4d 61 63 69 6e 74 6f 73 | 68 20 54 6f 6f 6c 62 6f |Macintos|h Toolbo|
|00005e70| 78 7d 0d 09 6b 50 72 65 | 65 6d 70 74 69 76 65 54 |x}..kPre|emptiveT|
|00005e80| 68 72 65 61 64 09 3d 20 | 32 3b 09 7b 74 68 72 65 |hread.= |2;.{thre|
|00005e90| 61 64 20 64 6f 65 73 6e | 27 74 20 6e 65 63 65 73 |ad doesn|'t neces|
|00005ea0| 73 61 72 69 6c 79 20 79 | 69 65 6c 64 7d 0d 4e 6f |sarily y|ield}.No|
|00005eb0| 74 65 3a 20 20 6b 50 72 | 65 65 6d 70 74 69 76 65 |te: kPr|eemptive|
|00005ec0| 54 68 72 65 61 64 20 69 | 73 20 6e 6f 74 20 64 65 |Thread i|s not de|
|00005ed0| 66 69 6e 65 64 20 66 6f | 72 20 75 73 65 20 77 69 |fined fo|r use wi|
|00005ee0| 74 68 20 70 6f 77 65 72 | 20 54 68 72 65 61 64 20 |th power| Thread |
|00005ef0| 4d 61 6e 61 67 65 72 2e | 0d 54 68 65 20 54 68 72 |Manager.|.The Thr|
|00005f00| 65 61 64 49 44 20 64 61 | 74 61 20 74 79 70 65 20 |eadID da|ta type |
|00005f10| 69 64 65 6e 74 69 66 69 | 65 73 20 69 6e 64 69 76 |identifi|es indiv|
|00005f20| 69 64 75 61 6c 20 74 68 | 72 65 61 64 73 2e 20 20 |idual th|reads. |
|00005f30| 54 68 72 65 61 64 49 44 | 73 20 61 72 65 20 75 6e |ThreadID|s are un|
|00005f40| 69 71 75 65 20 77 69 74 | 68 69 6e 20 74 68 65 20 |ique wit|hin the |
|00005f50| 73 63 6f 70 65 20 6f 66 | 20 74 68 65 20 61 70 70 |scope of| the app|
|00005f60| 6c 69 63 61 74 69 6f 6e | 20 70 72 6f 63 65 73 73 |lication| process|
|00005f70| 2e 20 20 20 54 68 65 72 | 65 20 61 72 65 20 61 20 |. Ther|e are a |
|00005f80| 66 65 77 20 70 72 65 2d | 64 65 66 69 6e 65 64 20 |few pre-|defined |
|00005f90| 73 79 6d 62 6f 6c 69 63 | 20 74 68 72 65 61 64 20 |symbolic| thread |
|00005fa0| 49 44 73 20 74 6f 20 6d | 61 6b 65 20 74 68 65 20 |IDs to m|ake the |
|00005fb0| 69 6e 74 65 72 66 61 63 | 65 20 65 61 73 69 65 72 |interfac|e easier|
|00005fc0| 2e 0d 54 59 50 45 0d 09 | 54 68 72 65 61 64 49 44 |..TYPE..|ThreadID|
|00005fd0| 09 3d 20 4c 4f 4e 47 49 | 4e 54 3b 0d 43 4f 4e 53 |.= LONGI|NT;.CONS|
|00005fe0| 54 0d 09 6b 4e 6f 54 68 | 72 65 61 64 49 44 09 3d |T..kNoTh|readID.=|
|00005ff0| 20 30 3b 09 7b 6e 6f 20 | 74 68 72 65 61 64 20 61 | 0;.{no |thread a|
|00006000| 74 20 61 6c 6c 7d 0d 09 | 6b 43 75 72 72 65 6e 74 |t all}..|kCurrent|
|00006010| 54 68 72 65 61 64 49 44 | 09 3d 20 31 3b 09 7b 74 |ThreadID|.= 1;.{t|
|00006020| 68 72 65 61 64 20 77 68 | 6f 73 65 20 63 6f 6e 74 |hread wh|ose cont|
|00006030| 65 78 74 20 69 73 20 63 | 75 72 72 65 6e 74 7d 0d |ext is c|urrent}.|
|00006040| 09 6b 41 70 70 6c 69 63 | 61 74 69 6f 6e 54 68 72 |.kApplic|ationThr|
|00006050| 65 61 64 49 44 09 3d 20 | 32 3b 09 7b 74 68 72 65 |eadID.= |2;.{thre|
|00006060| 61 64 20 63 72 65 61 74 | 65 64 20 66 6f 72 20 61 |ad creat|ed for a|
|00006070| 70 70 20 61 74 20 6c 61 | 75 6e 63 68 7d 0d 54 68 |pp at la|unch}.Th|
|00006080| 65 20 54 68 72 65 61 64 | 4f 70 74 69 6f 6e 73 20 |e Thread|Options |
|00006090| 64 61 74 61 20 74 79 70 | 65 20 73 70 65 63 69 66 |data typ|e specif|
|000060a0| 69 65 73 20 6f 70 74 69 | 6f 6e 73 20 74 6f 20 74 |ies opti|ons to t|
|000060b0| 68 65 20 4e 65 77 54 68 | 72 65 61 64 20 72 6f 75 |he NewTh|read rou|
|000060c0| 74 69 6e 65 2e 0d 54 59 | 50 45 0d 09 54 68 72 65 |tine..TY|PE..Thre|
|000060d0| 61 64 4f 70 74 69 6f 6e | 73 09 3d 20 4c 4f 4e 47 |adOption|s.= LONG|
|000060e0| 49 4e 54 3b 0d 43 4f 4e | 53 54 0d 09 6b 4e 65 77 |INT;.CON|ST..kNew|
|000060f0| 53 75 73 70 65 6e 64 20 | 09 3d 20 31 3b 09 7b 62 |Suspend |.= 1;.{b|
|00006100| 65 67 69 6e 20 6e 65 77 | 20 74 68 72 65 61 64 20 |egin new| thread |
|00006110| 69 6e 20 73 74 6f 70 70 | 65 64 20 73 74 61 74 65 |in stopp|ed state|
|00006120| 7d 0d 09 6b 55 73 65 50 | 72 65 6d 61 64 65 54 68 |}..kUseP|remadeTh|
|00006130| 72 65 61 64 20 09 3d 20 | 32 3b 09 7b 75 73 65 20 |read .= |2;.{use |
|00006140| 74 68 72 65 61 64 20 66 | 72 6f 6d 20 73 75 70 70 |thread f|rom supp|
|00006150| 6c 79 7d 0d 09 6b 43 72 | 65 61 74 65 49 66 4e 65 |ly}..kCr|eateIfNe|
|00006160| 65 64 65 64 20 09 3d 20 | 34 3b 09 7b 61 6c 6c 6f |eded .= |4;.{allo|
|00006170| 63 61 74 65 20 69 66 20 | 6e 6f 20 70 72 65 6d 61 |cate if |no prema|
|00006180| 64 65 20 65 78 69 73 74 | 73 7d 0d 09 6b 46 50 55 |de exist|s}..kFPU|
|00006190| 4e 6f 74 4e 65 65 64 65 | 64 20 09 3d 20 38 3b 09 |NotNeede|d .= 8;.|
|000061a0| 7b 64 6f 6e d5 74 20 73 | 61 76 65 20 46 50 55 20 |{don.t s|ave FPU |
|000061b0| 63 6f 6e 74 65 78 74 7d | 0d 09 6b 45 78 61 63 74 |context}|..kExact|
|000061c0| 4d 61 74 63 68 54 68 72 | 65 61 64 20 09 3d 20 31 |MatchThr|ead .= 1|
|000061d0| 36 3b 09 7b 66 6f 72 63 | 65 20 65 78 61 63 74 20 |6;.{forc|e exact |
|000061e0| 6d 61 74 63 68 20 6f 76 | 65 72 20 62 65 73 74 20 |match ov|er best |
|000061f0| 66 69 74 7d 0d 54 68 65 | 20 46 6f 6c 6c 6f 77 69 |fit}.The| Followi|
|00006200| 6e 67 20 69 6e 66 6f 72 | 6d 61 74 69 6f 6e 20 69 |ng infor|mation i|
|00006210| 73 20 73 75 70 70 6c 69 | 65 64 20 74 6f 20 61 20 |s suppli|ed to a |
|00006220| 63 75 73 74 6f 6d 20 73 | 63 68 65 64 75 6c 65 72 |custom s|cheduler|
|00006230| 2e 0d 4e 6f 74 65 3a 20 | 20 6b 46 50 55 4e 6f 74 |..Note: | kFPUNot|
|00006240| 4e 65 65 64 65 64 20 69 | 73 20 69 67 6e 6f 72 65 |Needed i|s ignore|
|00006250| 64 20 62 79 20 74 68 65 | 20 70 6f 77 65 72 20 54 |d by the| power T|
|00006260| 68 72 65 61 64 20 4d 61 | 6e 61 67 65 72 20 62 65 |hread Ma|nager be|
|00006270| 63 61 75 73 65 20 66 6c | 6f 61 74 69 6e 67 20 70 |cause fl|oating p|
|00006280| 6f 69 6e 74 20 72 65 67 | 69 73 74 65 72 73 20 61 |oint reg|isters a|
|00006290| 72 65 20 61 6c 77 61 79 | 73 20 73 61 76 65 64 2e |re alway|s saved.|
|000062a0| 0d 54 59 50 45 0d 53 63 | 68 65 64 75 6c 65 72 49 |.TYPE.Sc|hedulerI|
|000062b0| 6e 66 6f 52 65 63 50 74 | 72 09 3d 20 5e 53 63 68 |nfoRecPt|r.= ^Sch|
|000062c0| 65 64 75 6c 65 72 49 6e | 66 6f 52 65 63 3b 0d 53 |edulerIn|foRec;.S|
|000062d0| 63 68 65 64 75 6c 65 72 | 49 6e 66 6f 52 65 63 09 |cheduler|InfoRec.|
|000062e0| 3d 20 52 45 43 4f 52 44 | 0d 09 49 6e 66 6f 52 65 |= RECORD|..InfoRe|
|000062f0| 63 53 69 7a 65 3a 09 09 | 09 4c 4f 4e 47 49 4e 54 |cSize:..|.LONGINT|
|00006300| 3b 0d 09 43 75 72 72 65 | 6e 74 54 68 72 65 61 64 |;..Curre|ntThread|
|00006310| 49 44 3a 09 09 09 54 68 | 72 65 61 64 49 44 3b 0d |ID:...Th|readID;.|
|00006320| 09 53 75 67 67 65 73 74 | 65 64 54 68 72 65 61 64 |.Suggest|edThread|
|00006330| 49 44 3a 09 09 54 68 72 | 65 61 64 49 44 3b 0d 09 |ID:..Thr|eadID;..|
|00006340| 49 6e 74 65 72 72 75 70 | 74 65 64 43 6f 6f 70 54 |Interrup|tedCoopT|
|00006350| 68 72 65 61 64 49 44 3a | 09 54 68 72 65 61 64 49 |hreadID:|.ThreadI|
|00006360| 44 3b 0d 09 45 4e 44 3b | 0d 54 68 65 20 66 6f 6c |D;..END;|.The fol|
|00006370| 6c 6f 77 69 6e 67 20 61 | 72 65 20 74 68 65 20 74 |lowing a|re the t|
|00006380| 79 70 65 20 64 65 66 69 | 6e 69 74 69 6f 6e 73 20 |ype defi|nitions |
|00006390| 66 6f 72 20 61 20 74 68 | 72 65 61 64 27 73 20 65 |for a th|read's e|
|000063a0| 6e 74 72 79 20 72 6f 75 | 74 69 6e 65 2c 20 61 20 |ntry rou|tine, a |
|000063b0| 63 75 73 74 6f 6d 20 73 | 63 68 65 64 75 6c 69 6e |custom s|chedulin|
|000063c0| 67 20 72 6f 75 74 69 6e | 65 2c 20 20 63 75 73 74 |g routin|e, cust|
|000063d0| 6f 6d 20 63 6f 6e 74 65 | 78 74 20 73 77 69 74 63 |om conte|xt switc|
|000063e0| 68 69 6e 67 20 72 6f 75 | 74 69 6e 65 2c 20 61 6e |hing rou|tine, an|
|000063f0| 64 20 61 20 74 68 72 65 | 61 64 20 74 65 72 6d 69 |d a thre|ad termi|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.